【问题标题】:PHP: what is wrong in parsing this JSONPHP:解析这个 JSON 有什么问题
【发布时间】:2015-04-21 09:38:52
【问题描述】:

你能告诉我解析任何 JSON 输出有什么问题吗?

我正在使用此代码 $stats = json_decode($json, true);

    if ($stats == null && json_last_error() != JSON_ERROR_NONE) {
 throw new \LogicException(sprintf("Failed to parse json string '%s', error: '%s'", $json , json_last_error_msg()));

}

谢谢

【问题讨论】:

  • 如果您在jsonlint.com 的第一个链接中验证您的 JSON,您会看到错误

标签: php json parsing


【解决方案1】:

查看jsonlint,它突出显示返回为 NaN 的条目无效。这是因为它们是未引用的值。您需要在 JSON 的创建脚本中适应这一点,或者更改您的数据源以不返回 NaN 值。

【讨论】:

    【解决方案2】:

    在你的第一个 json 中你会看到错误

    "OrganicSocialShare":NaN,
    "PaidSocialShare":NaN,
    

    错误:字符串应该用双引号括起来。

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      • 2011-08-26
      相关资源
      最近更新 更多