我正在阅读一个 JSON 字符串,其中散布着 u'string' 样式的字符串。例子:
[
{
"!\/award\/award_honor\/honored_for": {
"award": {
"id": "\/en\/spiel_des_jahres"
},
"year": {
"value": "1996"
}
},
"guid": "#9202a8c04000641f80000000003a0ee6",
"type": "\/games\/game",
"id": "\/en\/el_grande",
"name": "El Grande"
},
{
"!\/award\/award_honor\/honored_for": {
"award": {
"id": "\/en\/spiel_des_jahres"
},
"year": {
"value": "1995"
}
},
"guid": "#9202a8c04000641f80000000000495ec",
"type": "\/games\/game",
"id": "\/en\/settlers_of_catan",
"name": "Settlers of Catan"
}
]
如果我指定 name = result.name。然后,当我将该值传递给 Django 模板时,它显示为 u'Dominion'
如何格式化它以显示为 Dominion?
++更新++
我认为问题与从列表或字典中打印值有关。例如:
result = freebase.mqlread(query)
games = {}
count = 0
r = result[0]
name = r.name
games["name"] = name,
self.response.out.write(games["name"])
self.response.out.write(name)
这显示为:
(u'Dominion',) // saved response to dictionary, and then printed
Dominion // when calling the value directly from the response
我需要遍历一组 JSON 项,并且这些值使用 unicode 显示。为什么?