0
{ 
    "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。

提前致谢...

PS 当第 25 行运行时出现错误:

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

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

我通过 JSONlint 验证了我的 JSON,并且出现了解析错误。

4

3 回答 3

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"
        }
    ]
}
于 2013-08-16T04:55:42.950 回答
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"

希望这会有所帮助

于 2013-08-16T04:56:08.403 回答
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"
        }
    ]
}
于 2013-08-16T05:00:01.587 回答