0
有很多关于解析twitter json的帖子,但没有人看到我解决了我的问题。使用json python解析unicoded tweet
这是代码
import json
file = open('tweet', 'r')
tweet = file.read()
#{"geo":null,"text":"Lmao!! what time? I dont finish evening cleaning till 5 RT \[email protected]_user: football anyone?.....i wanna have a kickabout :(\u201d"}
#{"geo":null,"text":"Lmao!! what time? I dont finish evening cleaning till 5 RT @some_user: football anyone?.....i wanna have a kickabout :("}
def parseStreamingTweet(tweet):
try:
singleTweetJson = json.loads(tweet)
for index in singleTweetJson:
if index == 'text':
print "text : ", singleTweetJson[index]
except ValueError:
print "Error ", tweet
print ValueError
return
parseStreamingTweet(tweet)
这是测试程序。鸣叫流入和检查目的,我已经保存在文件中的推文,并检查。有一个twitter feed的编辑部分。
任何人都可以说我如何解析单向编码的推文。评论中的第一条推文是uni编码,第二条不是。首先出现错误,同时删除uni-code字符串,解析成功。什么是解决方案?
谢谢!这工作!但我打印在unicode支持的终端(我正在使用Netbeans IDE,并且支持unicode),并且消息打印在异常中,但不在数组'文本'中,反正它工作!谢谢! – Curiousity 2012-03-10 16:15:39