Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //lib JSON didownload di: http://code.google.com/p/json-simple/
- //cara memasukkan lib ke project android: http://stackoverflow.com/questions/3642928/adding-a-library-jar-to-an-eclipse-android-project
- public ArrayList<TweetData> parser(String resBody) throws Exception {
- ArrayList<TweetData> alTweet = new ArrayList<TweetData>();
- JSONObject jsonObject = null;
- JSONParser parser=new JSONParser();
- try {
- Object obj = parser.parse(resBody);
- jsonObject=(JSONObject)obj;
- }catch(Exception ex){
- Log.e("yw","Exception parser: " + ex.getMessage());
- }
- JSONArray arr = null;
- try {
- Object j = jsonObject.get("results");
- arr = (JSONArray)j;
- } catch(Exception ex){
- Log.e("yw","Exception ambil result tweets: " + ex.getMessage());
- }
- if (arr!=null) {
- for(Object t : arr) {
- TweetData td=null;
- try {
- td = new TweetData(
- ((JSONObject)t).get("from_user").toString(),
- ((JSONObject)t).get("text").toString(),
- ((JSONObject)t).get("created_at").toString(),""
- );
- } catch (ParseException e) {
- Log.e("yw","Exception ambil detil tweet: " + e.getMessage());
- }
- alTweet.add(td);
- }
- } else
- {
- Log.e("yw","kosong: "+resBody);
- throw new Exception();
- }
- return alTweet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement