php自定义jsondecode,有些值没有用双引号括起来


php custom json_decode, some values are not enclosed by double quotations

我们的服务器没有最新的PHP版本,因此我无法使用json_decode。我试着使用PEAR:http://mike.teczno.com/JSON/JSON.phps,但数据集是巨大的,它得到了30秒的超时错误-30秒无论如何都是不可接受的运行时间。

我偶然发现:http://www.php.net/manual/en/function.json-decode.php#108552它几乎奏效了。

我的JSON是这样的形式:

[{"number1":3,"number2":5,"time":"Jul 30, 2012 1:05:07 PM","value1":"aa","value2":"bb"}]

正如您所看到的,"number1"answers"number2"字段的值没有用双引号括起来,这破坏了自定义json_decode。

有人知道如何修改或提供能够克服这一问题的json_decode吗?

正如评论中所建议的,我使用http://include-once.org/p/upgradephp这似乎是一个很好的json_decode()回退。

在PHP中添加:

header("Content-type: application/json");

在您的javascript中,使用:

// Fetch the JSON text
var jsonFetch = $.ajax({
   url:"http://localhost/yourphp.php",
   async:false,
   cache:false,
}).responseText;
// Parse it so it will more formatted the right way
jsonData = JSON.parse(jsonFetch);