51Testing软件测试论坛
标题:
Day1-8测试积点任务
[打印本页]
作者:
测试积点老人
时间:
2018-7-27 11:10
标题:
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[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是否还可以对已筛选的出的内容再次做检索。或者是还有其他的处理方法。非常感谢!
作者:
abcsell
时间:
2018-7-30 10:03
工具本身没有问题,可以做到这一点
作者:
qqq911
时间:
2018-7-30 12:49
可以再次筛检的
作者:
jingzizx
时间:
2018-7-30 13:24
保存后,再次筛检是否可以
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2