{
"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" }
]
}
由于某些原因,PHP的json_decode没有解码这个JSON。
提前致谢...
P.S。当第25行运行时,我收到错误:
$ temp = json_decode($ obj-> hints,true);
解析错误:语法错误, C:\ Program Files(x86)\ Zend \ Apache2 \ htdocs \ crosswords \ query.blockouts.php中的意外'hintsacross'(T_STRING)< / b>在线 25
我通过JSONlint验证了我的JSON,并且出现了解析错误。
答案 0 :(得分:5)
它是无效的JSON。尝试在“hintsdown”之前添加逗号并重试json_decode。
{
"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 :(得分:1)
$ll="{ "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" } ] } "
$ll = json_decode($ll);
print_r($ll);
在
附近添加(,)逗号],
"hintsdown"
希望这会有所帮助
答案 2 :(得分:1)
json的格式不正确。使用jsonlint.com进行检查。您将收到错误,如果json格式正确,您也会得到一条好消息。
Parse error on line 18:
...A10" } ]"hintsdown": [
---------------------^
Expecting 'EOF', '}', ',', ']'
纠正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"
}
]
}