Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Javascript中解析PHP生成的JSON_Php_Javascript_Json - Fatal编程技术网

无法在Javascript中解析PHP生成的JSON

无法在Javascript中解析PHP生成的JSON,php,javascript,json,Php,Javascript,Json,我有一个返回JSON字符串的php脚本 <?php $arr = array( 'id' => '1', 'myarray' => array( array('a' => 'a1', 'b' => 'b1', 'c' => 'c1', 'd' => 'd1'), array('a' => 'a2', 'b' => 'b2', 'c' => 'c2', 'd' => 'd2') ) ); echo json_encode($arr

我有一个返回JSON字符串的php脚本

<?php
$arr = array(
'id' => '1',
'myarray' => array(
array('a' => 'a1', 'b' => 'b1', 'c' => 'c1', 'd' => 'd1'),
array('a' => 'a2', 'b' => 'b2', 'c' => 'c2', 'd' => 'd2')
)
);

echo json_encode($arr);
?>
但是对于上面的代码,我得到了这个错误

SyntaxError: JSON Parse error: Unexpected identifier "object"

什么可能导致此错误?

问题在于您的ajax调用。您有
数据类型:“json”
,这意味着您的字符串已经在回调中被解析。 因此:


问题在于ajax调用。您有
数据类型:“json”
,这意味着您的字符串已经在回调中被解析。 因此:


假设持续时间是多少?您确定JS中的
json
变量是正确的字符串吗?您是如何检索它的?请向我们展示“json”的内容。假设持续时间是多少?您确定JS中的
json
变量是正确的字符串吗?您是如何检索它的?请向我们展示“json”的内容。
SyntaxError: JSON Parse error: Unexpected identifier "object"
 $.ajax({
    dataType: "json",
    url: "http://www.something.com/sendJson.php"
 }).done(function(json) {
    alert(json['id']);
 });