So, I'm working on an Android app that will read a JSON response from a remote server (running PHP). Everything works fine until I try to read the array data item from the larger JSON string. Below is the error Eclipse throws when it tries to parse the object into the array. Anyone have any ideas? JSONLint validates that this array is valid JSON, so I'm not sure what the issue is here.
Note - it DOES let me parse this element as a JSONObject, but I'm not clear how to get it from that to an associative array like I need. I do see that JSONObject has a method ToJSONArray, but it requires a list of array keys, but those are variable and I won't know what they are until I parse the damn array! Any assistance is appreciated.
public JSONArray parseJson(String jsonString) {
JSONArray data = new JSONArray();
try {
JSONObject json = new JSONObject(jsonString);
success = json.getBoolean("success");
object = json.getString("object");
message = json.getString("message");
data = json.getJSONArray("data")
} catch (JSONException e) {
Log.e("ServerResponse::parseJson", e.getMessage());
e.printStackTrace();
success = false;
message = "Error parsing return JSON data. " + e.getCause();
}
return data;
}
Here's the JSON array I'm trying to parse:
{
"1": {
"country_of_origin": "US",
"genre": "Action",
"date_finished": "2005-06-17",
"dtimemod": "2009-12-03 14:29:59",
"netflix_rating": "82",
"table": "movies",
"rotten_rating": "82",
"format": "Live Action",
"date_begun": "2005-06-17",
"id": "3055",
"dtimecre": "2009-12-03 14:29:59",
"name": "Batman Begins",
"user_id": "mcenci",
"year": "2005",
"actors": "Christian Bale, Michael Caine, Liam Neeson, Morgan Freeman, Gary Oldman, Ken Watanabe, Katie Holmes, Cillian Murphy, Tom Wilkinson, Rutger Hauer, Sara Stewart, Richard Brake, Gus Lewis",
"rating": "100",
"extra_info": "Runtime: 140 min\n",
"public": "0",
"notes": "",
"key": "103",
"genre2": "Sci-Fi"
}
}