我创建了一个facebook应用程序来与我的python脚本集成。 我有权从用户处获取通知和消息
问题是,当我收到通知时,我没有很好地处理它:
notification of Somebody is {u'title_text': u'Texas HoldEm Poker: Hurry! CLAIM your
$25,000 FREE CHIPS now!'}
正如您所看到的,“{u'title_text':u'…“}”不属于那里。 我怎样才能只收到里面的短信
第二个问题是,当我试图用希伯来语获取信息时,它看起来是这样的:
{u'title_text': u'\u200e\u200e\u05d7\u05df \u05d1\u05dc\u05d7\u05e0\u05e1\u200e posted
on Danie's\'s timeline\u200e: "Have a lot of good luck"'}
“\u200e\u200e\u05d7\u05df\u05d1\u05dc\u05d7\u05e0\u05e1\u200e”是希伯来语中某人的名字,如何将其编码为与名字本身一样完美
多谢各位
编辑:我发现unicode是“utf-8”,我需要在字符串之前添加“u” 但是,如果我的程序得到一个字符串,该怎么办呢?如何将“u”添加到现有字符串中? 谢谢
编辑:更新代码:
def insertNewNotification(notification_list, owner):
for notification in notification_list:
notification = repr(notification['title_text'])
notification = str(notification)
notification = unicode(notification, 'unicode-escape')
notification = notification.encode("UTF-8").decode("UTF-8")
print "notification of " + owner + " is " + notification
response = json.load(urllib.urlopen((url + "add_notification&message=" + notification + "&owner=" + owner).encode("UTF-8")))
return 1
{u'title_text': u'Texas HoldEm Poker: Hurry! CLAIM your $25,000 FREE CHIPS now!'}
是具有Unicode键和值的字典的表示(repr()
)u""
是Python中的Unicode文本。只能在Python源代码中键入u
您可能在某个地方有以下代码
print "notification of Somebody is", data
您应该改用
print data['title_text']
了解以下两者之间的区别:
相关问题 更多 >
编程相关推荐