我试过了:
# -*- coding: utf-8 -*-
with open("File1", "w") as outfile:
json.dump( {"Tytuł":"tą"}, outfile, indent = True, encoding="utf-8")
这给了我:
{
"Tytu\u0142": "t\u0105"
}
我想得到的是:
{
"Tytuł": "tą"
}
ensure_ascii=False
有效,但当我尝试从文件中获取JSON数据时,我得到UnicodeEncodeError: 'ascii' codec can't encode characters...
我使用的代码是:
json_data=open('File0')
data = json.load(json_data)
with open("File1", "w") as outfile:
json.dump( data,outfile,indent = True,ensure_ascii=False)
答案 0 :(得分:1)
尝试将参数ensure_ascii
设置为False:
with open("File1", "w") as outfile:
json.dump( {"Tytuł":"tą"}, outfile, indent = True, encoding="utf-8", ensure_ascii=False)