Stuck with Java json exception
Background: Have collected tweets from the streaming api to a textfile and successfully parsed each line to my java objects using json.org library. Great.
Problem: From the "text": -field I want to extract information, this works semi-good. I do however get this exception running my code:
org.json.JSONException: Expected a ',' or '}' at 1280 [character 1281 line 1]
Trying to locate where in my textfile this is, I only see regular characters and with the mindset that json.org lib does what it's supposed to do, why am I getting this? Where do I even begin?
This is line 1280 in my file. Character 1281 is a 'o' so I have no idea what I'm doing wrong.
{"retweet_count":null,"text":"Listening to Don't Get Me Wrong by Pretenders on @Grooveshark: http:\/\/tinysong.com\/o9ui #musicmonday #nowplaying","id_str":"28756412823","entities":{"urls":[{"indices":[63,87],"expanded_url":null,"url":"http:\/\/tinysong.com\/o9ui"}],"hashtags":[{"text":"musicmonday","indices":[88,100]},{"text":"nowplaying","indices":[101,112]}],"user_mentions":[{"id_str":"3806441","indices":[49,61],"screen_name":"Grooveshark","name":"Grooveshark","id":3806441}]},"coordinates":null,"retweeted":false,"in_reply_to_status_id":null,"place":null,"geo":null,"new_id_str":"608552371148029952","source":"web","new_id":608552371148029952,"truncated":false,"in_reply_to_status_id_str":null,"favorited":false,"in_reply_to_user_id_str":null,"created_at":"Tue Oct 26 03:40:05 +0000 2010","contributors":null,"user":{"follow_request_sent":null,"lang":"en","time_zone":"La Paz","id_str":"24490174","following":null,"profile_text_color":"666666","followers_count":466,"profile_background_image_url":"http:\/\/a3.twimg.com\/profile_background_images\/113185343\/x0f8a90fc4af7484f7a0c6c11d594f94.png","profile_link_color":"3399CC","description":"I'm a complex being. A bit of a nerd and a geek with social skills, as unlikely as that may sound. Active gamer. Lover of music, movies, books and food. ","listed_count":18,"notifications":null,"profile_background_tile":true,"statuses_count":17095,"profile_sidebar_fill_color":"202020","profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1117295836\/geekydot2_normal.jpg","location":"Dominican Republic","show_all_inline_media":false,"profile_use_background_image":false,"contributors_enabled":false,"friends_count":339,"profile_sidebar_border_color":"666666","protected":false,"screen_name":"dotina","geo_enabled":false,"created_at":"Sun Mar 15 05:06:39 +0000 2009","name":"Ligia Carri\u00f3n","favourites_count":0,"url":"http:\/\/geekydot.wordpress.com\/","id":24490174,"verified":false,"utc_offset":-14400,"profile_background_color":"202020"},"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"id":28756412823}
and here's the same thing, formatted:
{
"retweet_count": null,
"text": "Listening to Don't Get Me Wrong by Pretenders on @Grooveshark: http:\/\/tinysong.com\/o9ui #musicmonday #nowplaying",
"id_str": "28756412823",
"entities": {
"urls": [
{
"indices": [
63,
87
],
"expanded_url": null,
"url": "http:\/\/tinysong.com\/o9ui"
}
],
"hashtags": [
{
"text": "musicmonday",
"indices": [
88,
100
]
},
{
"text": "nowplaying",
"indices": [
101,
112
]
}
],
"user_mentions":开发者_如何学运维 [
{
"id_str": "3806441",
"indices": [
49,
61
],
"screen_name": "Grooveshark",
"name": "Grooveshark",
"id": 3806441
}
]
},
"coordinates": null,
"retweeted": false,
"in_reply_to_status_id": null,
"place": null,
"geo": null,
"new_id_str": "608552371148029952",
"source": "web",
"new_id": 608552371148029952,
"truncated": false,
"in_reply_to_status_id_str": null,
"favorited": false,
"in_reply_to_user_id_str": null,
"created_at": "Tue Oct 26 03:40:05 +0000 2010",
"contributors": null,
"user": {
"follow_request_sent": null,
"lang": "en",
"time_zone": "La Paz",
"id_str": "24490174",
"following": null,
"profile_text_color": "666666",
"followers_count": 466,
"profile_background_image_url": "http:\/\/a3.twimg.com\/profile_background_images\/113185343\/x0f8a90fc4af7484f7a0c6c11d594f94.png",
"profile_link_color": "3399CC",
"description": "I'm a complex being. A bit of a nerd and a geek with social skills, as unlikely as that may sound. Active gamer. Lover of music, movies, books and food. ",
"listed_count": 18,
"notifications": null,
"profile_background_tile": true,
"statuses_count": 17095,
"profile_sidebar_fill_color": "202020",
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/1117295836\/geekydot2_normal.jpg",
"location": "Dominican Republic",
"show_all_inline_media": false,
"profile_use_background_image": false,
"contributors_enabled": false,
"friends_count": 339,
"profile_sidebar_border_color": "666666",
"protected": false,
"screen_name": "dotina",
"geo_enabled": false,
"created_at": "Sun Mar 15 05:06:39 +0000 2009",
"name": "Ligia Carri\u00f3n",
"favourites_count": 0,
"url": "http:\/\/geekydot.wordpress.com\/",
"id": 24490174,
"verified": false,
"utc_offset": -14400,
"profile_background_color": "202020"
},
"in_reply_to_screen_name": null,
"in_reply_to_user_id": null,
"id": 28756412823
}
You might want to try another parser which could give you better error message.
Error itself suggests that this would occur within a JSON Object, after value, in which case it should be either followed by a comma separating following value, or '}' to end object. It is possible that line number could be off (which would be a bug). That's why it would be good to try to either indent input for testing (to get more accurate location) or to try smaller snippets.
精彩评论