坚持使用Java json异常

时间:2010-12-03 10:20:51

标签: java json exception-handling

背景:已经从流式api收集了一条推文到文本文件,并使用json.org库成功地将每一行解析为我的java对象。大。

问题:从“文本”: - 字段我想提取信息,这是半好的。但是,我确实运行了我的代码:

org.json.JSONException: Expected a ',' or '}' at 1280 [character 1281 line 1]

试图找到我的文本文件中的位置,我只看到常规字符和json.org lib做了它应该做的心态,为什么我得到这个?我从哪里开始?

这是我文件中的第1280行。 1281字符是'o'所以我不知道我做错了什么。

  

{“retweet_count”:null,“text”:“在@Grooveshark上听取伪装者的错误:http:\ / \ / tinysong.com \ / o9ui #musicmonday #nowplaying”,“id_str” : “28756412823”, “实体”:{ “网址”:[{ “指数”:[63,87], “expanded_url”:空, “URL”: “HTTP:\ / \ / tinysong.com \ / o9ui” }], “#标签”:[{ “文本”: “musicmonday”, “指数”:[88100]},{ “文本”: “nowplaying”, “指数”:[101112]}], “user_mentions”:[ { “ID_STR”: “3806441”, “指数”:[49,61], “SCREEN_NAME”: “的Grooveshark”, “名”: “的Grooveshark”, “ID”:3806441}]}, “坐标”:空, “转推”:假的, “in_reply_to_status_id”:空, “地方”:空, “地理”:空, “new_id_str”: “608552371148029952”, “源”: “网络”, “NEW_ID”:608552371148029952, “截断”: 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“,”follow“:null,”profile_text_color“:”666666“,”followers_count“:466, “profile_background_ima ge_url“:”http:\ / \ / a3.twimg.com \ / profile_background_images \ / 113185343 \ /x0f8a90fc4af7484f7a0c6c11d594f94.png“,”profile_link_color“:”3399CC“,”description“:”我是一个复杂的人。有点像一个书呆子和一个有社交技巧的极客,这听起来不太可能。积极的游戏玩家。音乐,电影,书籍和食物的爱好者。 “ ”listed_count“:18, ”通知“:空, ”profile_background_tile“:真实的, ”statuses_count“:17095, ”profile_sidebar_fill_color“: ”202020“, ”profile_image_url“:” HTTP:\ / \ / a0.twimg.com \ / profile_images \ / 1117295836 \ /geekydot2_normal.jpg“,”location“:”多米尼加共和国“,”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, ”验证“:假的, ”utc_offset“: - 14400,” profile_background_color “:” 202020 “},” in_reply_to_screen_name “:NULL,” in_reply_to_user_id “:空,” ID“:28756412823}

,这是同样的事情,格式化:

{
    "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
}

1 个答案:

答案 0 :(得分:1)

您可能想尝试另一种可以为您提供更好的错误消息的解析器。

错误本身表明这将发生在JSON对象中,在值之后,在这种情况下,它应该后跟逗号分隔后面的值,或者'}'到结束对象。 行号可能会关闭(这可能是一个错误)。这就是为什么尝试缩进输入以进行测试(获得更准确的位置)或尝试更小的片段会很好。