Android : How to correctly parse Reddit API in Android

on Sunday, July 6, 2014


So I've been trying to parse Reddits r/hot/.json API to get a list view of topic information but I cant seem to get my JSON right. I've looked everywhere and I cant seem to find a good example on how to do this for reddit. Here is what I have so far..



try {
JSONArray hotTopics = new JSONArray(result);
for(int i=0; i<hotTopics.length(); i++) {
JSONObject topic = hotTopics.getJSONObject(i);
String title = topic.getString("title");
String author = topic.getString("author");
String imageUrl = topic.getString("thumbnail");
String postTime = topic.getString("created_utc");
String rScore = topic.getString("score");

topicdata.add(new ListData(title, author, imageUrl, postTime, rScore));
}

} catch (JSONException e) {
e.printStackTrace();
}

0 comments:

Post a Comment