Back to project page AndroidTwitterApp.
The source code is released under:
MIT License
If you think the Android project AndroidTwitterApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.julienlecomte.apps.basictwitter.models; /* ww w .ja va 2s . c om*/ import java.util.ArrayList; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.text.Html; public class Tweet { private long uid; private String body; private String createdAt; private User user; public static Tweet fromJson(JSONObject jsonObject) { Tweet tweet = new Tweet(); try { tweet.uid = jsonObject.getLong("id"); tweet.body = Html.fromHtml(jsonObject.getString("text")).toString(); tweet.createdAt = jsonObject.getString("created_at"); tweet.user = User.fromJson(jsonObject.getJSONObject("user")); } catch (JSONException e) { e.printStackTrace(); return null; } return tweet; } public static ArrayList<Tweet> fromJsonArray(JSONArray jsonArray) { ArrayList<Tweet> tweets = new ArrayList<Tweet>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject; try { jsonObject = jsonArray.getJSONObject(i); } catch (JSONException e) { e.printStackTrace(); continue; } Tweet tweet = Tweet.fromJson(jsonObject); if (tweet != null) { tweets.add(tweet); } } return tweets; } public long getUid() { return uid; } public String getBody() { return body; } public String getCreatedAt() { return createdAt; } public User getUser() { return user; } }