I new to parsing JSON - up until this point, I've been purely XML. Anyways, I am using JSON (Java ME) to parse something with the following structure:
{"name" : "JACK","name" : "JILL","name" : "JOHN","name" : "JENNY","name" : "JAMES","name" : "JIM"}
Here is my code:
try {
JSONObject json = new JSONObject(response);
JSONArray jsonArray = outer.getJSONArray("name");
System.out.println("ARRAY SIZE:"
+ jsonArray.length());
} catch (JSONException ex) {
}
My problem is that I cannot even get the println("ARRAY SIZE:"...) statement to output at all in my Eclipse console. The only time that I am getting any sort of output is if I use the following code:
try {
JSONObject json = new JSONObject(response);
System.out.println("OUTPUT:"
+ json.getString("name"));
} catch (JSONException ex) {
}
...That seems to give me only the last element. Is there a reason why I cannot get the JSONArray to work? Is it because the JSON contains no "outer" key?
I'd appreciate any help. Thanks!