【发布时间】:2010-10-02 18:45:34
【问题描述】:
我有两个相似的 JSON 文件。我可以用json_decode() 阅读其中一个,但不能阅读另一个。
我已经把文件上传到www.huzursuz.com/json/json_test.rar
如果您想检查它们,brother_a.php 有效,而 brother.php 无效。
我认为问题不是json_decode 嵌套限制,因为文件非常相似。
【问题讨论】:
我有两个相似的 JSON 文件。我可以用json_decode() 阅读其中一个,但不能阅读另一个。
我已经把文件上传到www.huzursuz.com/json/json_test.rar
如果您想检查它们,brother_a.php 有效,而 brother.php 无效。
我认为问题不是json_decode 嵌套限制,因为文件非常相似。
【问题讨论】:
你从哪里得到这么大的 JSON 字符串?
根据json_decode 文档,如果 json 在某些方面格式不正确,它只会返回 NULL,这就是我在尝试 Brother.php 时得到的结果
// the following strings are valid JavaScript but not valid JSON
// the name and value must be enclosed in double quotes
// single quotes are not valid
$bad_json = "{ 'bar': 'baz' }";
json_decode($bad_json); // null
// the name must be enclosed in double quotes
$bad_json = '{ bar: "baz" }';
json_decode($bad_json); // null
// trailing commas are not allowed
$bad_json = '{ bar: "baz", }';
json_decode($bad_json); // null
编辑
我通过 JSON 验证器 JSONLint 运行了您的两个 JSON 文件,正如预期的那样,brother+a 文件通过了,而 brother 在一些地方出现了错误。
【讨论】: