我想用JSONPath解析它:
[
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4],
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
]
请帮忙吗?
答案 0 :(得分:34)
如果对象是:
[
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4],
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
]
然后"$[0]"
将返回:
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4]
"$[1]"
将返回:
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
你也可以做两级深度。 "$[0][4]"
将返回:
205
您还可以使用"$[*]"
将数组元素提取到列表中,该列表将返回2个元素的列表。第一个是:
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4]
,第二个是:
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
答案 1 :(得分:0)
使用DefiantJS,您可以使用XPath语法搜索JSON结构。该库使用搜索功能扩展了全局对象JSON。
在这种情况下,你可以写这样的东西;
var data = [
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4],
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
],
search = JSON.search( data, '//*/*/*' );
看看这个小提琴; http://jsfiddle.net/hbi99/5NfeM/
答案 2 :(得分:0)
这对我有用
JsonPath.with(jsonResponse).param("name", "getName").get("findAll { a -> a.name == name }")