TA的每日心情 | 擦汗 9 小时前 |
---|
签到天数: 527 天 连续签到: 4 天 [LV.9]测试副司令
|
1测试积点
问题:
关于获取 json 的某一 list 的某些字段问题
在以下的json中,我需要得到的几个字段是:当set.class.0非空的时候,返回该set列表中的某些字段
- {
- "code": 0,
- "msg": null,
- "data": {
- "set": [
- {
- "id": "1566", "type": 1,
- "class": { "0": [],"1": [ "460"],"2": ["460","460","461" ] },
- },
- {
- "id": "1788", "type": 1,
- "class": { "0": [ "461" ], "1": [], "2": [ "460" ]},
- },
- {
- "id": "1762","type": 1,
- "class": { "0": [],"1": [ "461" ], "2": [ "460" ],
- },
- {
- "id": "1790","type": 1,
- "class": { "0": [ "460","461"], "1": [], "2": [] },
- },
- {
- "id": "1792","type": 2,
- "class": {"0": [ "460", "461"], "1": [],"2": []
- },
- },]
- }}
复制代码 既是当存在"0": [ "461" ]与"0": [ "460", "461"]等”0“为非空内容时,取set[0]中的id,type与”0"的属性值,在此例子中,则是得到id=1788,type=1,"0"=461。我用jsonpath仅仅是实现了当set.class.0非空的时候,返回整个set:
- List<Object> list=JsonPath.read(string, "$.data.set[?(@.class.0.length()>0]");
复制代码 得到的结果是
- {
- "id": "1788", "type": 1,
- "class": { "0": [ "461" ], "1": [], "2": [ "460" ]},
- },
- {
- "id": "1790","type": 1,
- "class": { "0": [ "460","461"], "1": [], "2": [] },
- },
- {
- "id": "1792","type": 2,
- "class": {"0": [ "460", "461"], "1": [],"2": []},
- }
复制代码 疑问:若有使用过jsonpath的人,可否回答下jsonpath是否还可以对已筛选的出的内容再次做检索。或者是还有其他的处理方法。非常感谢!
|
|