添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account public static void main ( String [] args ) { String jsonString = "{state:{a:{check:['x','y']},b:{}},view:[{id:'a',name:'an'},{id:'b',name:'bn'}]}" ; System . out . println ( JSONPath . eval ( JSON . parseObject ( jsonString ), "$..view" )); String errorJsonString = "{state:{a:{check:['x',null,'y']},b:{}},view:[{id:'a',name:'an'},{id:'b',name:'bn'}]}" ; System . out . println ( JSONPath . eval ( JSON . parseObject ( errorJsonString ), "$..view" ));

示例代码里的 errorJsonString 相比 jsonString 中间的check数组多了一个 null 元素。

1.2.83版本下的异常堆栈

Exception in thread "main" java.lang.NullPointerException
	at com.alibaba.fastjson.JSONPath.deepScan(JSONPath.java:4034)
	at com.alibaba.fastjson.JSONPath.deepScan(JSONPath.java:4024)
	at com.alibaba.fastjson.JSONPath.deepScan(JSONPath.java:4024)
	at com.alibaba.fastjson.JSONPath.deepScan(JSONPath.java:4024)
	at com.alibaba.fastjson.JSONPath$PropertySegment.eval(JSONPath.java:2350)
	at com.alibaba.fastjson.JSONPath.eval(JSONPath.java:121)
	at com.alibaba.fastjson.JSONPath.eval(JSONPath.java:642)
	at FastjsonTest.main(FastjsonTest.java:16)
          

需要配置 Feature.AllowUnQuotedFieldNames

JSONPath.eval(
        JSON.parseObject(jsonString, Feature.AllowUnQuotedFieldNames),
        "$..view"

2.0.15版本已经发布,建议升级到最新版本
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn

需要配置 Feature.AllowUnQuotedFieldNames

JSONPath.eval(
        JSON.parseObject(jsonString, Feature.AllowUnQuotedFieldNames),
        "$..view"

2.0.15版本已经发布,建议升级到最新版本 https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn

谢谢回复,不过不是AllowUnQuotedFieldNames的问题,是数组解析是遇到null没判空的问题,我已经发了一个PR,麻烦合一下