I have a huge chunk, so large that I can't manually edit the file and need to read it in and do regex operations to see what's wrong.
Basically - my server is PHP 5.1.6 and I can't update it. This features an older json_decode
which is less featured than the 5.2/5.3 versions.
json_decode
returns NULL and json_last_error
is being invoked but the function doesn't exist except in PHP 5.3 so I'm manually trying to see what's wrong.
$regex = '#[^0-9"$a-zA-Z{:}().]#';
$json = preg_replace( $regex, '', $json );
$tree = json_decode ( $json, true );
var_dump($tree); // NULL
A snippet of the JSON.. somewhere in the middle
{"109":0,"103":1,"102":59,"101":70,"100":4299,"94":0,"50":51,"46":0,"45":0,"44":0,"43":0,"42":0,"23":0,"22":0,"18":0,"17":1,"16":1,"13":160,"8":4298}},"2":{"d":{"109":0,"103":92,"102":54,"101":53,"100":4301,"94":0,"50":4278,"49":328,"46":1,"45":0,"44":1,"43":0,"42":0,"26":0,"23":0,"22":0,"18":0,"17":1,"16":1,"8":4300},"m":{"94":1,"100":1,"26":1,"50":1,"8":1,"49":1,"18":1,"43":1,"42":1,"109":1},"c":{"/":{"d":{"109":0,"100":4301,"94":0,"50":4278,"49":328,"43":0,"42":0,"26":0,"18":0,"8":4300}},"G":{"d":{"109":1,"100":4303,"94"开发者_StackOverflow:1,"68":17,"50":64,"49":53,"43":1,"42":1,"34":0,"18":1,"13":2216,"11":0,"8":4302}}}},"3":
The }}}}
is suspicious but this probably just closes 4 nested object literals.
Would appreciate any insight.
Have you tried the PEAR Services_JSON class? It may give you a more useful error, and runs well on older versions of PHP.
I ran the data several times through the JSON formatter/validator and it was valid. The dataset is too huge that even using VIM to kill nested objects is a lot of work.
I was able to run this dataset locally, so I'm going to conclude it is an issue with the nested limit of 20 for PHP 5.1 where it gets bumped up in PHP 5.2 and 5.3.
精彩评论