2013-06-13 160 views
-2
{ 
"created_at": "Thu Jun 13 09:27:27 +0000 2013", 
"id": 345110157237297150, 
"id_str": "345110157237297152", 
"text": "@sagarzope2 good afternoon 2nd retweet", 
"source": "web", 
"truncated": false, 
"in_reply_to_status_id": 345109774226030600, 
"in_reply_to_status_id_str": "345109774226030593", 
"in_reply_to_user_id": 1512890215, 
"in_reply_to_user_id_str": "1512890215", 
"in_reply_to_screen_name": "sagarzope2", 
"user": { 
    "id": 1512890215, 
    "id_str": "1512890215", 
    "name": "sagar zope", 
    "screen_name": "sagarzope2", 
    "location": "", 
    "description": "", 
    "url": null, 
    "entities": { 
     "description": { 
      "urls": [] 
     } 
    }, 
    "protected": false, 
    "followers_count": 0, 
    "friends_count": 10, 
    "listed_count": 0, 
    "created_at": "Thu Jun 13 09:23:17 +0000 2013", 
    "favourites_count": 0, 
    "utc_offset": null, 
    "time_zone": null, 
    "geo_enabled": false, 
    "verified": false, 
    "statuses_count": 5, 
    "lang": "en", 
    "contributors_enabled": false, 
    "is_translator": false, 
    "profile_background_color": "C0DEED", 
    "profile_background_image_url": "", 
    "profile_background_image_url_https": "", 
    "profile_background_tile": false, 
    "profile_image_url": "", 
    "profile_image_url_https": "", 
    "profile_link_color": "0084B4", 
    "profile_sidebar_border_color": "C0DEED", 
    "profile_sidebar_fill_color": "DDEEF6", 
    "profile_text_color": "333333", 
    "profile_use_background_image": true, 
    "default_profile": true, 
    "default_profile_image": true, 
    "following": false, 
    "follow_request_sent": false, 
    "notifications": false 
}, 
"geo": null, 
"coordinates": null, 
"place": null, 
"contributors": null, 
"retweet_count": 0, 
"favorite_count": 0, 
"entities": { 
    "hashtags": [], 
    "symbols": [], 
    "urls": [], 
    "user_mentions": [ 
     { 
      "screen_name": "sagarzope2", 
      "name": "sagar zope", 
      "id": 1512890215, 
      "id_str": "1512890215", 
      "indices": [ 
       0, 
       11 
      ] 
     } 
    ] 
}, 
"favorited": false, 
"retweeted": false, 
"lang": "en" 

}JSON轉換到Java對象GSON

任何一個可以建議我需要在這個JSON轉換爲Java對象

+0

您的JSON也無效。 – NINCOMPOOP

+0

不認爲這是有效的JSON ...無處不在的錯誤 –

+0

我建議你通過Gson文檔。您似乎有過類似的問題在過去http://stackoverflow.com/questions/17064725/complex-json-to-java-object-conversion-using-gson再次沒有嘗試顯示 – Nishant

回答

0

我不知道爲什麼,但我會盡量類stucture回答這個問題..

首先,它取決於您的要求。例如,如果只需要幾個字段,則可以直接獲取它們,而無需解析json。

如果你想創建java對象,那麼你只需瞭解JSON的工作方式。

{} - >對象

[] - >陣列

,如果您有:{"foo":"bar"}

你的對象將是

public class Object { 
    private String foo; 
} 

如果您有:{"foo":"bar","innerObj":{"fizz":"buzz"}}

您的對象將是

public class Object { 
    private String foo; 
    private InnerObj innerObj; 
} 

public class InnerObj { 
    private String fizz; 
    private InnerObj innerObj; 
} 

現在請您考慮。

閱讀關於JSON:http://json.org/

得到像傑克遜或GSON庫。