如何防止Flask返回拉丁字符作为Unicode表示?例如,对于这类字符:http://graphemica.com/%C3%91
我的FlaskApp在MySQL数据库中执行SELECT,逐行检索,将它们添加到列表中,将列表存储到字典中,最后返回一个JSON。在
@app.route("/json")
def show_json():
avisos_dict = {}
records_list = []
query = "SELECT * FROM tjs_stage.avisos"
cur.execute(query)
con.commit()
records = cur.fetchall()
for row in records:
records_list.append(row)
avisos_dict['avisos'] = records_list
return jsonify(avisos_dict)
有人知道怎么解决这个问题吗?在
提前感谢;)
"Ñ"
和"\u00d1"
json字符串表示相同的U+00D1Unicode字符:注意:反斜杠是转义的,因为它在Python字符串文本中也是特殊的。在
要避免ascii编码的json,set ^{} to ^{} :
示例:
^{pr2}$要运行服务器(假设您将其保存到
app.py
),请执行以下操作:要测试它:
输出:
@Hareendra Chamara Philips在the comment中建议:
相关问题 更多 >
编程相关推荐