【发布时间】:2014-10-03 22:59:27
【问题描述】:
我试过了:
# -*- 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)
【问题讨论】: