Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. [ ] https://www.reddit.com/.json 0x70eb7ea8 NORMAL null
  2.  
  3. public class RedditFront {
  4. private static String frontPageURL = "https://www.reddit.com/.json";
  5. private static String jsonResponse = "";
  6.  
  7.  
  8. public static void redditFrontAll(final Context context) throws JSONException {
  9. Log.d("REDDIT", "got here");
  10.  
  11. JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
  12. frontPageURL, null, new Response.Listener<JSONObject>() {
  13. @Override
  14. public void onResponse(JSONObject response) {
  15. try {
  16. JSONObject data = response.getJSONObject("data");
  17. JSONArray children = data.getJSONArray("children");
  18. for (int i = 0; i < children.length(); i++) {
  19. JSONObject topic = children.getJSONObject(i);
  20.  
  21. String author = topic.getString("author");
  22. String imageUrl = topic.getString("thumbnail");
  23. String postTime = topic.getString("created_utc");
  24. String rScore = topic.getString("score");
  25. String title = topic.getString("title");
  26. Log.d("REDDIT_TITLE:", title);
  27. }
  28.  
  29. } catch (JSONException e) {
  30. e.printStackTrace();
  31. Toast.makeText(context,
  32. "Error: " + e.getMessage(),
  33. Toast.LENGTH_LONG).show();
  34. }
  35.  
  36. }
  37. },
  38. new Response.ErrorListener() {
  39.  
  40. @Override
  41. public void onErrorResponse(VolleyError error) {
  42. VolleyLog.d(TAG, "Error: " + error.getMessage());
  43. Toast.makeText(context,
  44. error.getMessage(), Toast.LENGTH_SHORT).show();
  45.  
  46. }
  47. });
  48. Log.d("JSON:", jsonResponse);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement