最近我得到了一个这样的JSON响应,我不熟悉,因为它没有任何:
字符用于分隔对象,因此我无法从中获取值。
{
"result": [
["id", "name", "origin_count", "destination_count"],
[1, "A S Peta", 0, 0],
[2, "Aachara", 0, 0]
]
}
答案 0 :(得分:2)
它几乎是JSONArray的压缩格式,我已经看过几次,有些系统使用它来降低传输的数据量。 您可以尝试这样的事情(编辑您的需求,因为这只是一个基本概念):
// Let us assume your JSON is loaded in jsonString variable
try {
JSONArray jsonArray = jsonString.getJSONArray("result");
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray jsonSubArray = jsonArray.getJSONArray(i);
for (int j = 0; j < jsonSubArray.length(); j++) {
// Will read a String or cast the element to String
// Also it might throw JSONException so you would probably want to handle that too
Log.d("element", "[" + i + "|" + j + "] = " + jsonSubArray.getString(j));
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}