陷入JavaJSON异常

陷入JavaJSON异常,java,json,exception-handling,Java,Json,Exception Handling,背景:已将推特从流式api收集到文本文件,并使用json.org库成功地将每一行解析到我的java对象。太好了 问题:从“文本”:-字段中,我想提取信息,这项工作半好。但是,我确实在运行代码时遇到此异常: org.json.JSONException: Expected a ',' or '}' at 1280 [character 1281 line 1] 试着在我的文本文件中找到它的位置,我只看到普通字符,而且我的思维方式是json.org lib做它应该做的事情,为什么我会得到这个?我从

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

问题:从“文本”:-字段中,我想提取信息,这项工作半好。但是,我确实在运行代码时遇到此异常:

org.json.JSONException: Expected a ',' or '}' at 1280 [character 1281 line 1]
试着在我的文本文件中找到它的位置,我只看到普通字符,而且我的思维方式是json.org lib做它应该做的事情,为什么我会得到这个?我从哪里开始呢

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

{“retweet\u count”:null,“text”:“在@Grooveshark:http:\/\/tinysong.com\/o9ui上通过冒充者收听不要弄错我的音乐”nowplaying,“id\u str”:“28756412823”,“实体”:{“url”:[{“index”:[63,87],“expanded\u url”:null,“url”:“http:\/\/\/tinysong.com\/o9ui}],“hashtags”:“{“text”:“musicmonday”,“index”:[88100],{“nowplaying”,“索引”:[101112]}],“用户”提到:[{“id_str”:“3806441”,“索引”:[49,61],“屏幕名称”:“Grooveshark”,“名称”:“Grooveshark”,“id”:3806441}],“坐标”:null,“转发”:false,“回复状态中的_id”:null,“地点”:null,“地理”:null,“新的_id_str”:“6085523771148029952”,“来源”:“web”,“新的_id”:60852371148029952,“截断”:false,”在回复用户时,创建时间:2010年10月26日星期二03:40:05+0000,投稿人:null,用户:{“跟踪请求发送”:null,lang:“en”,“时区:”“La Paz”,“id:”“str:”“24490174”,“跟踪”:null,“配置文件文本颜色:”“66666666”,“关注者数”:466,“配置文件背景图像url:”http:\/\/a3.twimg.com\/profile\u background\u images\/113185343\/x0f8a90fc4af7484f7a0c6c11d594f94.png“,“profile\u link\u color:“3399CC”,“description:”我是一个复杂的人,有点书呆子和极客,有社交技能,这听起来似乎不太可能。活跃的玩家。音乐、电影、书籍和食物的爱好者。”,“列表计数”:18,“通知”:空,“profile\u background\u tile:true,“status\u count”:17095,“profile\u sidebar\u fill\u color”:“202020”,“profile\u image\u url”:“http:\/\/a0.twimg.com\/profile\u images\/1117295836\/geekydot2\u normal.jpg”,“位置”:“多米尼加共和国”,“显示所有在线媒体”:false,“profile\u使用背景图像”:false,“贡献者启用”:false,“好友数”:339,”配置文件侧栏颜色:“666666”,“受保护”:false,“屏幕名称”:“dotina”,“geo启用”:false,“创建于”:“Sun Mar 15 05:06:39+0000 2009”,“name”:“Ligia Carri\u00f3n”,“Favorites\u count”:0,“url”:“http:\/\/geekydot.wordpress.com\/”,“id”:24490174,“已验证”:false,“utc\u偏移量”:-14400,“配置文件背景颜色”:“202020”“:null,”在对用户的回复中“id”:null,“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
}

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

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

我将从删除JSON中的内容开始,使其更小。若要尝试隔离错误,并将其精简为仅包含导致错误的部分,我将使用该部分更新您的帖子。您使用什么JSON解析twitter响应?还有,你在使用推特api吗?@TEG:我正在使用来自的库,我将研究删除内容,但我正在使用一个约20K行的文本文件,对推特的部分进行非常基本的提取和分析。