谢谢阅读.
背景:
我正在尝试读取以JSON格式返回数据的流式API提要,然后将此数据存储到pymongo collection.流API需要"Accept-Encoding" : "Gzip"标头.
发生了什么:
代码失败 json.loads 和输出 - Extra data: line 2 column 1 - line 4 column 1 (char 1891 - 5597)(请参阅下面的错误日志)
解析每个JSON对象时不会发生这种情况 - 它是随机发生的.
我的猜测是我在每个"x"正确的JSON对象之后遇到一些奇怪的JSON对象.
如果请求的数据有时被gzip,我确实参考了如何使用pycurl,有时候不是吗?和编码时误差反序列化从谷歌一个JSON对象,但至今一直在解决这个错误是不成功的.
有人可以帮帮我吗?
错误日志:
注意:下面的JSON对象的原始转储基本上是使用repr()打印字符串的原始表示而不解析CRLF/LF的方法.
'{"id":"tag:search.twitter.com,2005:207958320747782146","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:493653150","link":"http://www.twitter.com/Deathnews_7_24","displayName":"Death News 7/24","postedTime":"2012-02-16T01:30:12.000Z","image":"http://a0.twimg.com/profile_images/1834408513/deathnewstwittersquare_normal.jpg","summary":"Crashes, Murders, Suicides, Accidents, Crime and Naturals Death News From All Around World","links":[{"href":"http://www.facebook.com/DeathNews724","rel":"me"}],"friendsCount":56,"followersCount":14,"listedCount":1,"statusesCount":1029,"twitterTimeZone":null,"utcOffset":null,"preferredUsername":"Deathnews_7_24","languages":["tr"]},"verb":"post","postedTime":"2012-05-30T22:15:02.000Z","generator":{"displayName":"web","link":"http://twitter.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/Deathnews_7_24/statuses/207958320747782146","body":"Kathi Kamen Goldmark, Writers\xe2\x80\x99 Catalyst, Dies at 63 http://t.co/WBsNlNtA","object":{"objectType":"note","id":"object:search.twitter.com,2005:207958320747782146","summary":"Kathi Kamen Goldmark, Writers\xe2\x80\x99 Catalyst, Dies at 63 http://t.co/WBsNlNtA","link":"http://twitter.com/Deathnews_7_24/statuses/207958320747782146","postedTime":"2012-05-30T22:15:02.000Z"},"twitter_entities":{"urls":[{"display_url":"nytimes.com/2012/05/30/boo\xe2\x80\xa6","indices":[52,72],"expanded_url":"http://www.nytimes.com/2012/05/30/books/kathi-kamen-goldmark-writers-catalyst-dies-at-63.html","url":"http://t.co/WBsNlNtA"}],"hashtags":[],"user_mentions":[]},"gnip":{"language":{"value":"en"},"matching_rules":[{"value":"url_contains: …Run Code Online (Sandbox Code Playgroud)