测试积点老人 发表于 2018-7-27 11:10:48

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是否还可以对已筛选的出的内容再次做检索。或者是还有其他的处理方法。非常感谢!


abcsell 发表于 2018-7-30 10:03:45

工具本身没有问题,可以做到这一点

qqq911 发表于 2018-7-30 12:49:03

可以再次筛检的

jingzizx 发表于 2018-7-30 13:24:10

保存后,再次筛检是否可以
页: [1]
查看完整版本: Day1-8测试积点任务