我解析在应用中的一些JSON和我所遇到的阵列,有时有信息,其内解析jsonarray:尝试将jsonarray
{
"output": [
{
"id": "1521",
"name": "Apples",
}
]
}
,有时无关。 e.g
{
"output": [
[]
]
}
我被
JSONArray output = c.getJSONArray("output");
int outputLength = output.length();
for (int q = 0; q < outputLength; q++)
{
JSONObject d = outputs.getJSONObject(q);
id[q] = d.getInt("id");
name[q] = d.getString("name");
}
解析,但是当它到达空数组崩溃。 我收到以下错误,那么:
01-19 01:08:00.237: W/System.err(17627): org.json.JSONException: Value [] at 0 of type org.json.JSONArray cannot be converted to JSONObject
它崩溃,因为它试图将jsonarray转换成一个对象,你不能这样做,所以我试图让第一阵列中的输出搭配:
JSONArray add = output.getJSONArray(0);
但是也会崩溃,因为在第一个输出中它是一个对象而不是数组。 我无法访问或控制json提要,因此我暂时无法解析结果。
这是完美的谢谢:) – Howli