【发布时间】:2014-09-12 13:59:09
【问题描述】:
名称在 ("") 之间的我的 json 数据工作如下。
var_dump(json_decode('{"a":"foo","b":"bar"}', true));
但名称不在 ("") 之间不起作用:
var_dump(json_decode('{a:"foo",b:"bar"}', true)) ;
我的 json 数据来自另一台服务器,如下所示:
{a:"foo",b:"bar"}
以及 php 使用 json_encode 创建的那个 json。
$rows = array();
while($r = mysqli_fetch_assoc($sql)) {
$rows[] = $r;
}
return json_encode($rows)
但是 json_decode 为这个对象返回 NULL。
【问题讨论】:
-
那不是 JSON,而是 JavaScript Object Literals (JSOL)。 PHP 的普通 json_decode() 不支持它。使用更具体的解析器,或不可靠的补丁解决方法之一。
-
但这是由 json_encode 创建的。
-
不,当然不是。两种选择:How to parse this json with php?
-
好的,谢谢你的回答验证了我的 json