【发布时间】:2016-04-02 20:37:51
【问题描述】:
我一直在使用烧瓶和 jsonify 进行实验。有用。但不支持 utf-8 字符(土耳其字符)。我正在使用字典。
if api_key in key_list:
quotes = {
'ataturk':
['Hayatta En Hakiki Mursit Ilimdir Fendir',
'Birgün benim naciz bedenim'],
'mahatma gandhi':
['Happiness is when what you think, what you'
'say,and what you do are in harmony.']
}
get_quote = quotes[karakter(author.lower(), harfler)]
quote = {
'quotes': random.choice(get_quote),
}
return jsonify(quote)
我尝试过编码,但它不起作用。我在调试模式下收到此错误:
AttributeError: 'dict' 对象没有属性 'encode'
我该如何解决这个问题?
【问题讨论】:
-
你能解释一下为什么你想避免
"Birg\u00fcn"吗?那是完全有效的 JSON,当你解码 JSON 时,它将成为你想要的字符串。
标签: python-3.x utf-8 flask