PHP Parse错误与有效的JSON

时间:2013-08-16 05:10:50

标签: php json decode

我使用JSONLint验证了这个JSON,当我的脚本的第25行运行时,它看起来像:

$temp = json_decode( $obj->hints,true );

我得到了:

  

解析错误:语法错误, C:\ Program Files(x86)\ Zend \ Apache2 \ htdocs \ crosswords \ query.blockouts.php中的意外'hintsacross'(T_STRING)< / b>在线 25

出来的剧本。我想知道如何使这个解析错误消失。这是JSON:

{
   "hintsacross": [ 
         { "number": "1", "hinttext": "Hurt", "hintsquare": "A1" }, 
         { "number": "5", "hinttext": "Make a selection", "hintsquare": "A6" },
         { "number": "8", "hinttext": "Frank", "hintsquare": "A10" } ], 
   "hintsdown": [ 
         { "number": "1", "hinttext": "First Greek letter", "hintsquare": "A1" },
         { "number": "2", "hinttext": "Used footnotes", "hintsquare": "A2" }, 
         { "number": "3", "hinttext": "Listened to", "hintsquare": "A3" } ] 
} 

提前致谢...

1 个答案:

答案 0 :(得分:2)

确保将有效字符串传递给json_decode函数。

 $myArray = json_decode("{"k":1}",1); // wont work as the input json string breaks

并将字符串添加为

 $myArray = json_decode('{"k":1}',1); // works