简体   繁体   English

需要帮助调试大量JSON数据

[英]Need help debugging a huge chunk of JSON data

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. 基本上-我的服务器是PHP 5.1.6,我无法更新它。 This features an older json_decode which is less featured than the 5.2/5.3 versions. 它具有较旧的json_decode ,其功能不如5.2 / 5.3版本。

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. json_decode返回NULL且正在调用json_last_error ,但该功能仅在PHP 5.3中不存在,因此我正在手动尝试json_last_error问题所在。

$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 中间的某处JSON的代码段

{"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":1,"68":17,"50":64,"49":53,"43":1,"42":1,"34":0,"18":1,"13":2216,"11":0,"8":4302}}}},"3": {“ 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”: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. }}}}是可疑的,但这可能只关闭4个嵌套对象文字。

Would appreciate any insight. 将不胜感激。

Have you tried the PEAR Services_JSON class? 您是否尝试过PEAR Services_JSON类? It may give you a more useful error, and runs well on older versions of PHP. 它可能会给您带来更有用的错误,并且可以在旧版本的PHP上很好地运行。

I ran the data several times through the JSON formatter/validator and it was valid. 我通过JSON格式化程序/验证程序多次运行了数据,它是有效的。 The dataset is too huge that even using VIM to kill nested objects is a lot of work. 该数据集太大,以至于即使使用VIM杀死嵌套对象也需要大量工作。

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. 我能够在本地运行此数据集,所以我将得出结论,这是一个问题,PHP 5.1的嵌套限制为20,在PHP 5.2和5.3中它被提高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM