Skip to content

Instantly share code, notes, and snippets.

@csdear
Created March 5, 2014 22:16
Show Gist options
  • Select an option

  • Save csdear/9cdbb57cd1efabb9890c to your computer and use it in GitHub Desktop.

Select an option

Save csdear/9cdbb57cd1efabb9890c to your computer and use it in GitHub Desktop.
parseJSON
private String[] mRawFeeds = new String[3];
private String[] mProcessedFeeds = new String[3];
private static final int NUM_FRIENDS = 3;
=======================
// Called when new Tweets have been downloaded
public void setRefreshed(String[] feeds) {
mRawFeeds[0] = feeds[0];
mRawFeeds[1] = feeds[1];
mRawFeeds[2] = feeds[2];
parseJSON();
updateFeed();
mIsFresh = true;
};
=====================================
public void parseJSON() {
JSONArray[] JSONFeeds = new JSONArray[NUM_FRIENDS];
for (int i = 0; i < NUM_FRIENDS; i++) {
try {
JSONFeeds[i] = new JSONArray(mRawFeeds[i]);
} catch (JSONException e) {
e.printStackTrace();
}
String name = "";
String tweet = "";
JSONArray tmp = JSONFeeds[i];
// string buffer for twitter feeds
StringBuffer tweetRec = new StringBuffer("");
for (int j = 0; j < tmp.length(); j++) {
try {
tweet = tmp.getJSONObject(j).getString("text");
JSONObject user = (JSONObject) tmp.getJSONObject(j).get(
"user");
name = user.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
tweetRec.append(name + " - " + tweet + "\n\n");
}
mProcessedFeeds[i] = tweetRec.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment