PHP:JSON解码限制

问题描述:

使用此代码:

$json = file_get_contents($this->url, true); 
$decode = json_decode($json, true); 

foreach ($decode as $key => $value) {
 ...
}

很简单,嗯?

传递带有最多500个数组元素的$ json ...可以正常使用!

Passing a $json with up to 500 array elements.... works right!

超过该限制...错误是:

Above that limit... the error is:

警告:为中的foreach()提供了无效的参数 /c/website/retriever/WsGlassRetriever.php,第19行

Warning: Invalid argument supplied for foreach() in /c/website/retriever/WsGlassRetriever.php on line 19

该函数的参数是否有内存限制?

Is there some memory limit for that function's argument?

我在文档中什么都没找到.我的版本是带有Suhosin-Patch 0.9.7(cli)的PHP 5.2.17-rnx1.1

I didn't found nothing about it in the docs. My version is PHP 5.2.17-rnx1.1 with Suhosin-Patch 0.9.7 (cli)

json_decode返回NULL.我刚刚在1000个元素的数组上成功进行了测试,并且运行得很好.

json_decode returns NULL if there is an error in the JSON syntax. I've just successfully tested on an array of 1000 elements and it ran just fine.

仔细检查您的JSON格式是否正确.甚至只有单引号而不是双引号之类的小东西,或者忘记在引号中加上属性名称,或者使用32-127范围以外的字符而未在UTF-8中正确编码的情况都可能导致这些问题.

Double-check that your JSON is correctly formatted. Even something as small as having single quotes instead of double, or forgetting to put a property name in quotes, or using a character outside the 32-127 range without correctly encoding it in UTF-8 can cause these problems.