0

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

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

我得到一个:

解析错误:语法错误,第25C:\Program Files (x86)\Zend\Apache2\htdocs\crosswords\query.blockouts.php中的意外 'hintscross' (T_STRING)

出来剧本。我想知道如何使这个解析错误消失。这是 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" } ] 
} 

提前致谢...

4

1 回答 1

2

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

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

并把字符串像

 $myArray = json_decode('{"k":1}',1); // works
于 2013-08-16T05:19:06.103 回答