Created
October 26, 2018 14:09
-
-
Save solidpple/fbce3827fd149e5b7564857aa23f8513 to your computer and use it in GitHub Desktop.
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
import org.json.JSONArray; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
public class Application { | |
public static void main(String args[]) throws JSONException { | |
String result = "{ \"code\": 100, \"data\": [ { \"audioKey\": \"3be93db8c30c45261c64799d9c180b0e\", \"author\": { \"dispname\": \"Evenloop\", \"image\": \"\", \"username\": \"evenloop\" }, \"channel_image\": \"\", \"count_listen\": 0, \"count_recommend\": 0, \"created_at\": 1439563223, \"is_recommended\": 0, \"title\": \"test title\" }, { \"audioKey\": \"d83ebae5058b36a264fd16772b5eaeb6\", \"author\": { \"dispname\": \"Evenloop\", \"image\": \"\", \"username\": \"evenloop\" }, \"channel_image\": \"\", \"count_listen\": 1, \"count_recommend\": 1, \"created_at\": 1438153623, \"is_recommended\": 1, \"title\": \"test title\" } ], \"mesg\": \"success\", \"method\": \"get\", \"target\": \"/api/feed\", \"time\": 0.3364}"; | |
JSONObject jsonObject = new JSONObject(result); | |
// { } Json Object, [] Json Array | |
// Feed List | |
System.out.println(result); | |
JSONArray feedArray = (JSONArray) jsonObject.get("data"); | |
for (int i = 0; i < feedArray.length(); i++) { | |
JSONObject feedObject = (JSONObject) feedArray.get(i); | |
System.out.println("Feed Data = " + feedObject.get("audioKey")); | |
JSONObject authorObject = (JSONObject) feedObject.get("author"); | |
System.out.println("Feed Data = " + authorObject.get("image")); | |
System.out.println("Feed Data = " + authorObject.get("dispname")); | |
System.out.println("Feed Data = " + authorObject.get("username")); | |
System.out.println("Feed Data = " + feedObject.get("channel_image")); | |
System.out.println("Feed Data = " + feedObject.get("count_listen")); | |
System.out.println("Feed Data = " + feedObject.get("count_recommend")); | |
System.out.println("Feed Data = " + feedObject.get("created_at")); | |
System.out.println("Feed Data = " + feedObject.get("is_recommended")); | |
System.out.println("Feed Data = " + feedObject.get("title")); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment