如何处理当REST服务响应作为Json : for返回时:
[{"boolField":true,"intField":991, "StringField":"SampleString"},
{"boolField":false, "intField":998, "StringField": "SampleString2"}]";我看到的所有博客和例子都没有处理上述场景。例如,我研究了http://goessner.net/articles/JsonPath/表达式语法,但找不到解决方案。
例如,下面的json,如果我想获得所有作者,我可以使用$.store.book[*].author或$..author
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}]}
}但是,如果像下面这样返回REST服务响应,那么如何从列表中获取所有作者
[
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
]发布于 2016-01-04 15:06:38
$..author将检索所有作者。
通常,当根对象是数组时,您可以将$看作一个数组,并执行类似于$[0]的操作来检查第一个项(但是仍然会得到一个数组)。
发布于 2017-11-24 19:26:02
在我的例子中,[0].author起作用了(我忽略了$)。
https://stackoverflow.com/questions/34589823
复制相似问题