I am trying to make an android app that fetch posts from my wordpress blog that displays the information in a list. I am able to get the results like title, description,etc but i am not able to get nested object "tags" from the JSON result. So, can you explain me how i can get the tag names from the JSON result from this JSON Response.
I am trying to use the following code :
JSONObject root = new JSONObject(postJSON);
JSONArray postsArray = root.getJSONArray("posts");
for (int i = 0; i < postsArray.length(); i++) {
// Get a single post at position i within the list of earthquakes
JSONObject currentPost = postsArray.getJSONObject(i);
String title = currentPost.getString("title");
Log.e(LOG_TAG, "title is " + title);
JSONObject tags = currentPost.getJSONArray("tags").getJSONObject(0);
String tag = tags.getString("name");
Log.e(LOG_TAG, "tag is " + tag);
Post post = new Post(title,"123", tag);
posts.add(post);
}
But the logcat is showing that the value can't be converted to JSONArray.