简体   繁体   English

使用JSONPATH解析JSON数组文件

[英]Parse JSON array file with JSONPATH

I want to parse this with JSONPath: 我想用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]
]

Can you help with that please? 你可以帮忙吗?

If the object is: 如果对象是:

[
  [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]
]

Then "$[0]" will return: 然后"$[0]"将返回:

[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4]

And "$[1]" will return: 并且"$[1]"将返回:

[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]

You can do it two levels deep as well. 你也可以做两级深度。 "$[0][4]" will return: "$[0][4]"将返回:

205

You can also extract the elements of the array into a list with "$[*]" , which will return a list of 2 elements. 您还可以使用"$[*]"将数组元素提取到列表中,该列表将返回2个元素的列表。 The first being: 第一个是:

[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4]

and the second being: 第二个是:

[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]

Using DefiantJS, you can search a JSON structure with XPath syntax. 使用DefiantJS,您可以使用XPath语法搜索JSON结构。 This library extends the global object JSON with a search function. 该库使用搜索功能扩展了全局对象JSON。

In this scenario, you can write something like this; 在这种情况下,你可以写这样的东西;

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, '//*/*/*' );

Check out this fiddle; 看看这个小提琴; http://jsfiddle.net/hbi99/5NfeM/ http://jsfiddle.net/hbi99/5NfeM/

这适合我

JsonPath.with(jsonResponse).param("name", "getName").get("findAll { a -> a.name == name  }")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM