Note that there are some explanatory texts on larger screens.

plurals
  1. POParse and store nested JSON data in android
    primarykey
    data
    text
    <p>I have to parse and store jSON data of facebook page.My JSON data is <a href="https://graph.facebook.com/344128252278047/feed?access_token=CAAUJS8OQ520BAB1VlcMib0nZBRVCZCkQQhd2feiF5nkG0a2mZAtZAz6lFStkz21UJWO14XXwzEaZCxJgRl5FZCZCbdRZCjRBGBY1w6Rv2Fxy5CX6xiTQVMizE6Y6u5C2zJPtXZBXCZCo9Pc8GvlXQJ6xBD8XQUQ4SGULgYgeHJRgLDir6QuY1Q4G180SNI0wcb7l4JMePMkI1B0LPYvBgW0rFI62F4Fg4CTVVGDIqKUNMLlAZDZD" rel="nofollow">this</a> . I have used getter setter for store data in Arraylist. <strong>Getter Setter class</strong></p> <pre><code>public class FBStatus { private String postId, category, name, catId, story, picture, type, status_type, objectId, createdTime, updatedTime, shareCount; public String getCategory() { return category; } public String getPostId() { return postId; } public void setPostId(String postId) { this.postId = postId; } public String getCatId() { return catId; } public void setCatId(String catId) { this.catId = catId; } public void setCategory(String category) { this.category = category; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStory() { return story; } public void setStory(String story) { this.story = story; } public String getPicture() { return picture; } public void setPicture(String picture) { this.picture = picture; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getStatus_type() { return status_type; } public void setStatus_type(String status_type) { this.status_type = status_type; } public String getObjectId() { return objectId; } public void setObjectId(String objectId) { this.objectId = objectId; } public String getCreatedTime() { return createdTime; } public void setCreatedTime(String createdTime) { this.createdTime = createdTime; } public String getUpdatedTime() { return updatedTime; } public void setUpdatedTime(String updatedTime) { this.updatedTime = updatedTime; } public String getShareCount() { return shareCount; } public void setShareCount(String shareCount) { this.shareCount = shareCount; } public class Likes { private String id, name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } class Comment { private String id, name, commenterId, message, createdTime, likecount; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCommenterId() { return commenterId; } public void setCommenterId(String commenterId) { this.commenterId = commenterId; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getCreatedTime() { return createdTime; } public void setCreatedTime(String createdTime) { this.createdTime = createdTime; } public String getLikecount() { return likecount; } public void setLikecount(String likecount) { this.likecount = likecount; } } } </code></pre> <p><strong>Parsing code</strong></p> <pre><code>private ArrayList&lt;FBStatus&gt; mData = new ArrayList&lt;FBStatus&gt;(); JsonParsing parsing = new JsonParsing(); jObj = parsing.getJSONFromUrl(FB_COMMENT + mAccessToken); try { data = jObj.getJSONArray(TAG_DATA); for (int i = 0; i &lt; data.length(); i++) { FBStatus bean = new FBStatus(); JSONObject c = data.getJSONObject(i); bean.setPostId(c.getString(TAG_ID)); JSONObject fromElement = new JSONObject(data.getJSONObject(i) .getString(TAG_FROM)); if (fromElement != null) { bean.setCategory(fromElement.getString(TAG_CATEGORY)); bean.setCatId(fromElement.getString(TAG_ID)); bean.setName(fromElement.getString(TAG_NAME)); } JSONObject shareElement = new JSONObject(data.getJSONObject(i) .getString(TAG_SHARE)); if (shareElement != null) { bean.setShareCount(shareElement.getString(TAG_SHARE_COUNT)); } JSONObject likesObj = new JSONObject(data.getJSONObject(i) .getString(TAG_LIKES)); JSONArray likesArray = likesObj.getJSONArray(TAG_DATA); for (int index = 0; index &lt; likesArray.length(); index++) { JSONObject likesElement = likesArray.getJSONObject(index); Likes like = bean.new Likes(); like.setId(likesElement.getString(TAG_ID)); like.setName(likesElement.getString(TAG_NAME)); // mData.add(); } JSONObject commentObj = new JSONObject(data.getJSONObject(i) .getString(TAG_COMMENT)); JSONArray commentArray = commentObj.getJSONArray(TAG_DATA); for (int index = 0; index &lt; commentArray.length(); index++) { JSONObject commentElement = commentArray .getJSONObject(index); String commentId = commentElement.getString(TAG_ID); String commentMsg = commentElement.getString(TAG_MESSAGE); String commentCreatedTime = commentElement .getString(TAG_CREATED_TIME); String commentLikeCount = commentElement .getString(TAG_LIKE_COUNT); JSONObject fromCommentElement = new JSONObject(commentArray .getJSONObject(index).getString(TAG_FROM)); if (fromCommentElement != null) { String commentName = fromCommentElement .getString(TAG_NAME); String commenterId = fromCommentElement .getString(TAG_ID); } } bean.setStory(c.getString(TAG_STORY)); bean.setPicture(c.getString(TAG_PICTURE)); bean.setType(c.getString(TAG_TYPE)); bean.setStatus_type(c.getString(TAG_STATUS_TYPE)); bean.setObjectId(c.getString(TAG_OBJECT_ID)); bean.setCreatedTime(c.getString(TAG_CREATED_TIME)); bean.setUpdatedTime(c.getString(TAG_UPDATED_TIME)); mData.add(bean); } } catch (JSONException e) { e.printStackTrace(); } </code></pre> <p>Using this code I'm able to store parent elements data in arraylist but challenge in this how to to store data of nested element like likes and comments. Please suggest me how to solve this issue.Your valuable suggestion will be great appreciated.Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload