I'm doing a json parser for java. I receive the json as string and then i try to get all the keys-value
Here is my Json string
{ "Message":{"field": [ {"bit":2,"name":"AAA"}, {"bit":3,"name":"BBB"}]}}
And here is my parser:
JSONObject jObject = new JSONObject(result); //result contains the json
JSONArray info = jObject.getJSONArray("field");
for (int i = 0 ; i < info.length(); i++) {
JSONObject obj = info.getJSONObject(i);
Iterator<String> keys = obj.keys();
while (keys.hasNext()) { //I use key - value cause the json can change
String key = keys.next();
System.out.println("Key: " + key + "\tValue: " + obj.get(key));
}
}
But everytime that i run the code i get:
Error parsing json org.json.JSONException: JSONObject["field"] not found.
And i guess the field its a JsonArray... Am i wrong?
Thank you for your time