-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 对象所需的类结构吗

4

1 回答 1

0

我不知道为什么,但我会尝试回答这个问题..

首先,这取决于您的要求。例如,如果您只需要几个字段,您可以直接获取它们,而无需解析 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/

获取 Jackson 或 GS​​ON 之类的库。

于 2013-06-13T10:56:41.127 回答