2013-06-13 47 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库。