简体   繁体   English

解析一个JSON数组,其中包含一个子数组

[英]Parsing a JSON Array which has a sub-array within

I get JSON from an URL in the following format: 我从URL获取JSON,格式如下:

{
"type":"test-aggregate",
"key":["loc999",2015,4,11,0],
"aggregated":[
[3,0,0,0,0,[1,2,1,2,1,1,2],41,63,[10,20,30,40,50,60,70],[10,20,30,40,50,60,70],[10,20,30,40,50],[10,20,30,40,50],[30,40,20,10,60],[30,40,20,10,60],[["75050",111],["75071",11]],[["75071",222],["75050",22]] ],
[3,1,5,1,1,[0,1,0,0,0,0,0],49,55,[11,22,33,44,55,66,77],[11,22,33,44,55,66,77],[11,22,33,44,55],[11,22,33,44,55],[33,44,22,11,66],[33,44,22,11,66],[["75050",111],["75071",11]],[["75071",222],["75050",22]] ]
]
}

Please note that, I don't get the data in Key-Value pair format. 请注意,我没有获得键值对格式的数据。 I need to take the values from "aggregated" key and need to parse each row as shown below for row 1: 我需要从“聚合”键中获取值,并需要解析每一行,如下所示:

column1: 3
Column2: 0
Column3: 0
Column4: 0
Column5: 0
Column6: 1
Column7: 2
Column8: 1
Column9: 2
Column10: 1
Column11: 1
Column12: 2
and so on.

If you notice above, Column6 to Column12 has the values from a sub-array parsed. 如果您在上面注意到,从Column6到Column12解析了子数组中的值。

Any help on how I can get this done in Java? 我如何用Java完成这项工作有任何帮助吗? I would help me a great extent if anyone could give me a solution. 如果有人可以给我解决方案,我将在很大程度上帮助我。

Thanks in Advance. 提前致谢。

You can make a new variable of the type List . 您可以创建类型为List的新变量。 There's a List method called addAll() which you can use to add all the elements of the subarray to the entire List. 有一个名为addAll()List方法,可用于将子addAll()所有元素添加到整个List中。

You will have to go through each element of the array, and use the addAll() method to add everything into one list. 您将必须遍历数组的每个元素,并使用addAll()方法将所有内容添加到一个列表中。

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

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