0
我有测试表,当通过SQL查询网址检索给出了这样的:解析谷歌的融合表JSON
{
"kind": "fusiontables#sqlresponse",
"columns": [
"index",
"name",
"latitude",
"longitude",
"address"
],
"rows": [
[
"1",
"Shop1",
"28.575326",
"77.32237",
"Sector 19"
],
[
"2",
"Shop2",
"43.34343",
"44.34343",
"Setor 18"
]
]
}
我无法解析此JSON。它期望在数组开头的JSOn对象:
"rows": [
如何解析这种JSON?在我看到的所有例子中,它都需要一个key_value对和一个对象(在数组中以“{”开头而不是“[”)。
我用下面的代码解析:
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
contacts = json.getJSONArray(TAG_ROWS);
// looping through All Contacts
for(int i = 0; i < contacts.length(); i++){
JSONObject c = contacts.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_INDEX);
}
} catch (JSONException e) {
e.printStackTrace();
}
它抛出JSONEXception在行
JSONObject c = contacts.getJSONObject(i);
*您如何解析此JSON?请添加代码。 – 2012-08-06 10:17:27
对不起。我认为这个问题是不言自明的。现在添加解析代码。 – deeJ 2012-08-06 10:38:52