fastjson之JSONPath

2023-03-03  本文已影响0人  爱的旋转体

json-path不能为空,json字符串也不能为空

1、json字符串中没有所要的字段,返回null

JSONArray jsonArray = JSONPath.compile("$.user.address").eval("{\"user\":{}}", JSONArray.class);
System.out.println(jsonArray);
image.png

2、json字符串中有所要的字段

JSONArray jsonArray = JSONPath.compile("$.user.address").eval("{\"user\":{\"address\":[]}}", JSONArray.class);
System.out.println(jsonArray);
image.png
上一篇 下一篇

猜你喜欢

热点阅读