【问题标题】:PHP json_decode JSON string not decodingPHP json_decode JSON字符串不解码
【发布时间】:2013-08-18 10:21:03
【问题描述】:
{ 
    "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。

提前谢谢...

附:第 25 行运行时出现错误:

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

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

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

【问题讨论】:

  • 向我们展示您正在使用的代码块
  • invalid json.. comma(,) is missing newr by ], "hintsdown": [

标签: php json decode


【解决方案1】:

这是无效的 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"
        }
    ]
}

【讨论】:

  • 顺便说一句,它有助于使用在线工具或其他验证器验证您的 JSON(我使用 JSONLint)
【解决方案2】:
   $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"

希望这会有所帮助

【讨论】:

    【解决方案3】:

    json 格式不正确。使用jsonlint.com 进行检查。您将收到错误消息,如果 json 格式正确,您也会收到一条 OK 消息。

    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"
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2016-07-04
      • 2012-07-06
      • 1970-01-01
      相关资源
      最近更新 更多