I have a JSON string and U want to get the name and add fields. I've tried to use several libraries and follow many tutorials, but was unsuccessful.
I thing my problem is that i have several arrays together...
inputLine =
{"posts":[
{"post":{
"name":"name1",
"add":"add1"}},
{"post":{
"name":"name2",
"add":"add2"}}
]
}
JSONObject obj_posts = new JSONObject(inputLine);
JSONArray menuitemArray = obj_posts.getJSONArray("posts");
JSONObject obj_post = new JSONObject(menuitemArray.getJSONObject(0).toString());
JSONObject menuitem = obj_post.getJSONObject("post");
JSONArray obj_post1 = menuitem.names();
At this point I can only access the key name and add, not the values.
inputLineisn't declared as aString, and if it was, it doesn't properly escape the quotes...)new JSONObjectthe second time. You don't need to parse the "inner JSON".menuitemArray.getJSONObject(0).getJSONObject("post");