Day1-8测试积点任务
问题:关于获取 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中的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是否还可以对已筛选的出的内容再次做检索。或者是还有其他的处理方法。非常感谢!
工具本身没有问题,可以做到这一点 可以再次筛检的 保存后,再次筛检是否可以
页:
[1]