【发布时间】:2016-07-07 02:08:13
【问题描述】:
我有一个这样的 JSON 结果:
jArr:
[
["53","54","55","62","63","64"],
["1133 Budapest Dráva utca 10.","1106 Budapest Örs vezér tere 25.","1106 Budapest Örs vezér tere 25.","1106 Budapest Örs vezér tere 25.","1133 Budapest Dráva utca 10.","1106 Budapest Örs vezér tere 25."],
[
["2016-08-18","15:00:00"],
["2016-04-08","13:00:00"],
["2016-04-08","14:00:00"],
["2016-04-08","10:00:00"],
["2016-04-08","13:00:00"],
["2016-04-08","15:00:00"]
]
]
我想在 java 中将它处理成 3 个数组。
我想要第一个 [](如 53、54...)到 int[] id。
第二个[] 到String[] 数组中,第三个也是一个字符串。
3个数组大小相同,但JSON结果可大可小。
java:
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend));
HttpResponse httpResponse = client.execute(post);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
JSONArray jArr = new JSONArray(result);
int size = 30;
String[] dates = new String[size];
String[] places = new String[size];
int[] ids = new int[size];
if (jArr.length() != 0) {
for (int i = 0; i < jArr.length(); i++){
//I think it should be processed here
ids[i] = jArr[0][i].getInt(i); //or something like that, but it doesn't work
places[i] = jArr[1][i].getSting();
dates[i] = jArr[2][i].getSting();
}
}
我应该如何将 JSON 处理成这些数组?
【问题讨论】:
标签: java arrays json multidimensional-array