[英]Decode JSON stringify in a different php file
<script>
function getstaff(){
var staffinfo = $('#group').val();
var myJSONText = JSON.stringify(staffinfo);
$.ajax({
type:"POST",
data:{data:myJSONText},
url:"staffDetails.php",
success: function(result){
alert(result);
}
});
}
</script>
How do I retrieve the posted data in staffDetails.php file. 如何检索staffDetails.php文件中的已发布数据。 It some how gives me drastic errors.
它给我带来了严重的错误。 Can anyone suggest how exactly to retrieve what I sent to this php file
任何人都可以建议如何准确地检索我发送到此php文件的内容
<?php
$data = JSON.parse($_POST['data'],',');
echo $data;
?>
Use json_decode
to decode a json array in PHP
使用
json_decode
在PHP
解码json数组
$data = json_decode($_POST['data']);
http://php.net/manual/en/function.json-decode.php http://php.net/manual/zh/function.json-decode.php
http://php.net/manual/en/function.json-decode.php http://php.net/manual/zh/function.json-decode.php
<?php
$data = json_decode($_POST['data']);
print_r($data);
?>
Try this: 尝试这个:
<?php
$data = json_decode($_POST['data'],true);
print_f($data); // return data in associative array.
?>
In PHP there is function: 在PHP中有功能:
json_decode($_POST['data']);
use it. 用它。
JSON.parse
is the function of Javascript so it will not work in php. 是Javascript的功能,因此无法在php中使用。
Read this: json_decode . 阅读: json_decode 。
suppose you have array like 假设你有像这样的数组
`{"1":{"1":"Employer+EID","2":"File+Creation+Date","3":"File+Creation+Time","4":"Payer+EID","5":"Payer+QID","6":"Payer+Bank+Short+Name","7":"Payer+IBAN","8":"Salary+Year+and+Montd","9":"Total+Salaries","10":"Total+records","11":"","12":"","13":"","14":"","15":""}}
you can read in php with : 您可以使用以下方式在php中阅读:
$data = json_decode($_POST['data'],true); $ data = json_decode($ _ POST ['data'],true);
echo $data[1][1]; echo $ data [1] [1]; use logic to cycle through data.
使用逻辑循环遍历数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.