Last active
August 5, 2016 04:55
-
-
Save 64lines/b2130eb365d9c319ec0a505c36dcf764 to your computer and use it in GitHub Desktop.
Get JSON Data to put it into an Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public List<Comment> obtainList(String jsonResponse) { | |
| List<Comment> commentList = new ArrayList<>(); | |
| try { | |
| JSONArray jsonArray = new JSONArray(jsonResponse); | |
| for (int i = 0; i < jsonArray.length(); i++) { | |
| JSONObject jsonObject = jsonArray.getJSONObject(i); | |
| Comment comment = new Comment(); | |
| comment.setId(jsonObject.get("pk").toString()); | |
| comment.setScore(jsonObject.getJSONObject("fields").get("score").toString()); | |
| comment.setUserId(jsonObject.getJSONObject("fields").get("user").toString()); | |
| comment.setComment(jsonObject.getJSONObject("fields").get("comment").toString()); | |
| comment.setConferenceId(jsonObject.getJSONObject("fields").get("conference").toString()); | |
| commentList.add(comment); | |
| } | |
| } catch (JSONException e) { | |
| e.printStackTrace(); | |
| } | |
| return commentList; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment