Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ ] https://www.reddit.com/.json 0x70eb7ea8 NORMAL null
- public class RedditFront {
- private static String frontPageURL = "https://www.reddit.com/.json";
- private static String jsonResponse = "";
- public static void redditFrontAll(final Context context) throws JSONException {
- Log.d("REDDIT", "got here");
- JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
- frontPageURL, null, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- JSONObject data = response.getJSONObject("data");
- JSONArray children = data.getJSONArray("children");
- for (int i = 0; i < children.length(); i++) {
- JSONObject topic = children.getJSONObject(i);
- String author = topic.getString("author");
- String imageUrl = topic.getString("thumbnail");
- String postTime = topic.getString("created_utc");
- String rScore = topic.getString("score");
- String title = topic.getString("title");
- Log.d("REDDIT_TITLE:", title);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(context,
- "Error: " + e.getMessage(),
- Toast.LENGTH_LONG).show();
- }
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- VolleyLog.d(TAG, "Error: " + error.getMessage());
- Toast.makeText(context,
- error.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- Log.d("JSON:", jsonResponse);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement