我一直在以JSon格式存储大量的推文。既然我正在尝试将它们读回状态,那么对象创建只会填充一些字段,即使原始Json包含所有信息。
这是原始JSON
{"createdAt":"Aug 5, 2014 4:03:39 PM",
"id":496733290263760896,
"text":"RT @lucasfresno: Bora se encacha?ar! RT @zerohora: Leia agora em http://t.co/ho1jjRsIpH http://t.co/VPRDdg35oO",
"source":"\u003ca href\u003d\"http://twitter.com/download/iphone\" rel\u003d\"nofollow\"\u003eTwitter for iPhone\u003c/a\u003e",
"isTruncated":false,
"inReplyToStatusId":-1,
"inReplyToUserId":-1,
"isFavorited":false,
"retweetCount":0,
"isPossiblySensitive":false,
"contributorsIDs":[],
"retweetedStatus":{"createdAt":"Aug 5, 2014 1:39:46 PM",
"id":496697079394492417,
"text":"Bora se encacha?ar! RT @zerohora: Leia agora em http://t.co/ho1jjRsIpH http://t.co/VPRDdg35oO",
"source":"\u003ca href\u003d\"http://twitter.com/download/iphone\" rel\u003d\"nofollow\"\u003eTwitter for iPhone\u003c/a\u003e",
"isTruncated":false,
"inReplyToStatusId":496694316656381952,
"inReplyToUserId":13531162,
"isFavorited":false,
"inReplyToScreenName":"zerohora",
"retweetCount":76,
"isPossiblySensitive":false,
"contributorsIDs":[],
"userMentionEntities":[{"name":"Zero Hora",
"screenName":"zerohora",
"id":13531162,
"start":23,
"end":32}],
"urlEntities":[{"url":"http://t.co/ho1jjRsIpH",
"expandedURL":"http://zh.com.br",
"displayURL":"zh.com.br",
"start":48,
"end":70}],
"hashtagEntities":[],
"mediaEntities":[{"id":496694316467646464,
"url":"http://t.co/VPRDdg35oO",
"mediaURL":"http://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg",
"mediaURLHttps":"https://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg",
"expandedURL":"http://twitter.com/zerohora/status/496694316656381952/photo/1",
"displayURL":"pic.twitter.com/VPRDdg35oO",
"sizes":{"0":{"width":150,"height":150,"resize":101},"1":{"width":340,"height":375,"resize":100},"2":{"width":477,"height":527,"resize":100},"3":{"width":477,"height":527,"resize":100}},
"type":"photo",
"start":71,
"end":93}],
"currentUserRetweetId":-1,
"user":{"id":49315012,
"name":"Lucas Silveira",
"screenName":"lucasfresno",
"location":"Em tudo que ? lugar.",
"description":"Fresno, Beeshop, SIRsir, Visconde, Vaconaut \u0026 The Apple Monster, Dark Matter, Poop Straps...",
"descriptionURLEntities":[],
"isContributorsEnabled":false,
"profileImageUrl":"http://pbs.twimg.com/profile_images/378800000615174403/68c2ac7b73415c6e06d71f8330b50d55_normal.jpeg",
"profileImageUrlHttps":"https://pbs.twimg.com/profile_images/378800000615174403/68c2ac7b73415c6e06d71f8330b50d55_normal.jpeg",
"url":"http://www.fresnorock.com.br",
"isProtected":false,
"followersCount":883117,
"profileBackgroundColor":"FFFFFF",
"profileTextColor":"666666",
"profileLinkColor":"2FC2EF",
"profileSidebarFillColor":"252429",
"profileSidebarBorderColor":"181A1E",
"profileUseBackgroundImage":true,
"showAllInlineMedia":false,
"friendsCount":628,
"createdAt":"Jun 21, 2009 10:34:03 AM",
"favouritesCount":80,
"utcOffset":-10800,
"timeZone":"Brasilia",
"profileBackgroundImageUrl":"http://pbs.twimg.com/profile_background_images/414221729/space.jpg",
"profileBackgroundImageUrlHttps":"https://pbs.twimg.com/profile_background_images/414221729/space.jpg",
"profileBackgroundTiled":false,
"lang":"en",
"statusesCount":55070,
"isGeoEnabled":true,
"isVerified":true,
"translator":false,
"listedCount":8724,
"isFollowRequestSent":false}},
"userMentionEntities":[{"name":"Lucas Silveira",
"screenName":"lucasfresno",
"id":49315012,
"start":3,
"end":15},
{"name":"Zero Hora",
"screenName":"zerohora",
"id":13531162,
"start":40,
"end":49}],
"urlEntities":[{"url":"http://t.co/ho1jjRsIpH",
"expandedURL":"http://zh.com.br",
"displayURL":"zh.com.br",
"start":65,
"end":87}],
"hashtagEntities":[],
"mediaEntities":[{"id":496694316467646464,
"url":"http://t.co/VPRDdg35oO",
"mediaURL":"http://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg",
"mediaURLHttps":"https://pbs.twimg.com/media/BuSc2WcCcAA49F5.jpg",
"expandedURL":"http://twitter.com/zerohora/status/496694316656381952/photo/1",
"displayURL":"pic.twitter.com/VPRDdg35oO",
"sizes":{"0":{"width":150,"height":150,"resize":101},"1":{"width":340,"height":375,"resize":100},"2":{"width":477,"height":527,"resize":100},"3":{"width":477,"height":527,"resize":100}},
"type":"photo",
"start":88,
"end":110}],
"currentUserRetweetId":-1,
"user":{"id":25413124,
"name":"Mariana Mussi",
"screenName":"MarianaMussi",
"location":"Brazil",
"description":"Minky Momo is here...E sigam-me os bons! Ps: Sou um docinho sim, mas ?s vezes posso ser de maracuj? ou lim?o ;) ? http://about.me/mariana.mussi",
"descriptionURLEntities":[],
"isContributorsEnabled":false,
"profileImageUrl":"http://pbs.twimg.com/profile_images/3487510187/6545498cd8cd7605637d9458c4c9e272_normal.jpeg",
"profileImageUrlHttps":"https://pbs.twimg.com/profile_images/3487510187/6545498cd8cd7605637d9458c4c9e272_normal.jpeg",
"url":"http://www.facebook.com/profile.php?id\u003d1106187557",
"isProtected":false,
"followersCount":391,
"profileBackgroundColor":"FFBDCF",
"profileTextColor":"41474D",
"profileLinkColor":"4DABC7",
"profileSidebarFillColor":"F7FBFC",
"profileSidebarBorderColor":"FFFFFF",
"profileUseBackgroundImage":true,
"showAllInlineMedia":false,
"friendsCount":386,
"createdAt":"Mar 19, 2009 8:46:35 PM",
"favouritesCount":4991,
"utcOffset":-10800,
"timeZone":"Brasilia",
"profileBackgroundImageUrl":"http://pbs.twimg.com/profile_background_images/195172436/minkymomomarianamussibg5.png",
"profileBackgroundImageUrlHttps":"https://pbs.twimg.com/profile_background_images/195172436/minkymomomarianamussibg5.png",
"profileBannerImageUrl":"https://pbs.twimg.com/profile_banners/25413124/1355939835",
"profileBackgroundTiled":true,
"lang":"pt",
"statusesCount":38951,
"isGeoEnabled":true,
"isVerified":false,
"translator":false,
"listedCount":9,
"isFollowRequestSent":false}
}
这是来自Status s = TwitterObjectFactory.createStatus(line)的Object结果;调用
StatusJSONImpl{
createdAt=null,
id=496733290263760896,
text='RT @lucasfresno: Bora se encacha?ar! RT @zerohora: Leia agora em http://t.co/ho1jjRsIpH http://t.co/VPRDdg35oO',
source='<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>',
isTruncated=false,
inReplyToStatusId=-1,
inReplyToUserId=-1,
isFavorited=false,
isRetweeted=false,
favoriteCount=-1,
inReplyToScreenName='null',
geoLocation=null,
place=null,
retweetCount=-1,
isPossiblySensitive=false,
lang='null',
contributorsIDs=[],
retweetedStatus=null,
userMentionEntities=[],
urlEntities=[],
hashtagEntities=[],
mediaEntities=[],
symbolEntities=[],
currentUserRetweetId=-1,
user=UserJSONImpl{
id=25413124,
name='Mariana Mussi',
screenName='null',
location='Brazil',
description='Minky Momo is here...E sigam-me os bons! Ps: Sou um docinho sim, mas ?s vezes posso ser de maracuj? ou lim?o ;) ? http://about.me/mariana.mussi',
isContributorsEnabled=false,
profileImageUrl='null',
profileImageUrlHttps='null',
isDefaultProfileImage=false,
url='http://www.facebook.com/profile.php?id=1106187557',
isProtected=false,
followersCount=-1,
status=null,
profileBackgroundColor='null',
profileTextColor='null',
profileLinkColor='null',
profileSidebarFillColor='null',
profileSidebarBorderColor='null',
profileUseBackgroundImage=false,
isDefaultProfile=false,
showAllInlineMedia=false,
friendsCount=-1,
createdAt=null,
favouritesCount=-1,
utcOffset=-1,
timeZone='null',
profileBackgroundImageUrl='null',
profileBackgroundImageUrlHttps='null',
profileBackgroundTiled=false,
lang='pt',
statusesCount=-1,
isGeoEnabled=false,
isVerified=false,
translator=false,
listedCount=-1,
isFollowRequestSent=false
}
}
有没有人解决过这个问题?我还没有找到任何实际的解决方案。 在此先感谢您的帮助。
编辑:我从GIT下载了源代码并在本地修复了createStatus方法。尽管如此,似乎现在应该已经修复了这个问题,除非有一些我遗漏的东西......答案 0 :(得分:1)
问题是,你想要完成什么? 创建一个JSONObject然后使用Status执行任何操作都会更容易。 Twitter4j有一个JSONObject接口,或者你可以使用org.json,如果你想要,例如转推的状态,你只需要从你存储的Json中获取它。
JSONObject json = new JSONObject(line);
System.out.println(json.get("retweeted_status"));
<强>更新强>
你的原始JSON是错误的,你有retweetedStatus
而不是retweeted_status
作为RT字段,这就是你总是得到NULL的原因。一个JSON表单就像这样
{
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"coordinates": null,
"created_at": "Wed Oct 22 18:05:19 +0000 2014",
"truncated": false,
"in_reply_to_user_id_str": null,
"source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>",
"retweeted_status": {
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"coordinates": null,
"created_at": "Wed Oct 22 17:58:08 +0000 2014",
"truncated": false,
"in_reply_to_user_id_str": null,
"source": "<a href=\"http://itunes.apple.com/us/app/twitter/id409789998?mt=12\" rel=\"nofollow\">Twitter for Mac</a>",
"retweet_count": 6,
"retweeted": false,
"geo": null,
"in_reply_to_screen_name": null,
"entities": {
"urls": [],
"hashtags": [
{
"indices": [
91,
101
],
"text": "Microsoft"
},
{
"indices": [
102,
110
],
"text": "Windows"
},
{
"indices": [
129,
140
],
"text": "LeyZamudio"
}
],
"user_mentions": [
{
"indices": [
46,
52
],
"screen_name": "Corfo",
"id_str": "57015564",
"name": "Corfo",
"id": 57015564
}
],
"symbols": []
},
"id_str": "524983055652360192",
"in_reply_to_user_id": null,
"favorite_count": 4,
"id": 524983055652360200,
"text": "El Chileno tiene derecho a postular a capital @Corfo Pero q NO te dejen postular x NO usar #Microsoft #Windows es Discriminación #LeyZamudio",
"place": null,
"contributors": null,
"lang": "es",
"user": {
"utc_offset": null,
"friends_count": 780,
"profile_image_url_https": "https://pbs.twimg.com/profile_images/492125365293568000/qsIuWYjP_normal.jpeg",
"listed_count": 34,
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme14/bg.gif",
"default_profile_image": false,
"favourites_count": 135,
"description": "Músico & Geek; Marido & Papá. Co-Fundador & Director Ejecutivo de @pantalla_cl; stay hungry, stay foolish (Steve Jobs -June 2005)",
"created_at": "Tue Mar 11 12:53:02 +0000 2008",
"is_translator": false,
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme14/bg.gif",
"protected": false,
"screen_name": "andresreitze",
"id_str": "14122556",
"profile_link_color": "009999",
"is_translation_enabled": false,
"id": 14122556,
"geo_enabled": true,
"profile_background_color": "131516",
"lang": "es",
"profile_sidebar_border_color": "EEEEEE",
"profile_location": null,
"profile_text_color": "333333",
"verified": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/492125365293568000/qsIuWYjP_normal.jpeg",
"time_zone": null,
"url": "http://t.co/IodqmRZoS7",
"contributors_enabled": false,
"profile_background_tile": true,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/14122556/1398980661",
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [
{
"display_url": "facebook.com/Pantalla.cl",
"indices": [
0,
22
],
"expanded_url": "http://www.facebook.com/Pantalla.cl",
"url": "http://t.co/IodqmRZoS7"
}
]
}
},
"statuses_count": 26786,
"follow_request_sent": false,
"followers_count": 1269,
"profile_use_background_image": true,
"default_profile": false,
"following": false,
"name": "Andrés Reitze",
"location": "Santiago, Chile",
"profile_sidebar_fill_color": "EFEFEF",
"notifications": false
},
"favorited": false
},
"retweet_count": 6,
"retweeted": false,
"geo": null,
"in_reply_to_screen_name": null,
"entities": {
"urls": [],
"hashtags": [
{
"indices": [
109,
119
],
"text": "Microsoft"
},
{
"indices": [
120,
128
],
"text": "Windows"
},
{
"indices": [
139,
140
],
"text": "LeyZamudio"
}
],
"user_mentions": [
{
"indices": [
3,
16
],
"screen_name": "andresreitze",
"id_str": "14122556",
"name": "Andrés Reitze",
"id": 14122556
},
{
"indices": [
64,
70
],
"screen_name": "Corfo",
"id_str": "57015564",
"name": "Corfo",
"id": 57015564
}
],
"symbols": []
},
"id_str": "524984861342564352",
"in_reply_to_user_id": null,
"favorite_count": 0,
"id": 524984861342564350,
"text": "RT @andresreitze: El Chileno tiene derecho a postular a capital @Corfo Pero q NO te dejen postular x NO usar #Microsoft #Windows es Discrim…",
"place": null,
"contributors": null,
"lang": "es",
"user": {
"utc_offset": -10800,
"friends_count": 1419,
"profile_image_url_https": "https://pbs.twimg.com/profile_images/458940469443952641/k4W4RMkF_normal.jpeg",
"listed_count": 5,
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/83201515/TWITTER.jpg",
"default_profile_image": false,
"favourites_count": 7,
"description": "",
"created_at": "Thu Jan 21 20:37:37 +0000 2010",
"is_translator": false,
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/83201515/TWITTER.jpg",
"protected": false,
"screen_name": "estebanmmp",
"id_str": "107197310",
"profile_link_color": "009999",
"is_translation_enabled": false,
"id": 107197310,
"geo_enabled": true,
"profile_background_color": "131516",
"lang": "es",
"profile_sidebar_border_color": "EEEEEE",
"profile_location": null,
"profile_text_color": "333333",
"verified": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/458940469443952641/k4W4RMkF_normal.jpeg",
"time_zone": "Santiago",
"url": null,
"contributors_enabled": false,
"profile_background_tile": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/107197310/1398254745",
"entities": {
"description": {
"urls": []
}
},
"statuses_count": 2354,
"follow_request_sent": false,
"followers_count": 390,
"profile_use_background_image": true,
"default_profile": false,
"following": false,
"name": "ESTEBAN MMP",
"location": "viña del mar, chile",
"profile_sidebar_fill_color": "EFEFEF",
"notifications": false
},
"favorited": false
}
您如何存储数据?你需要调用TwitterObjectFactory.getRawJSON(status)
来获取原始JSON。可能你没有这样做,这就是为什么twitterobjectfactory.createstatus返回转发的状态总是为空。