Python 在将数据写入 json 文件时,一般可采用如下:

import json

with open('test.json', 'w') as fp:
    json.dump(test_datas, fp)

但,对于中文来说,打开写入后的 json 文件,会出如 \u91d1\u534e 的情况,而不是显示中文.

此时,需要设置 ensure_ascii=False,如:

import json

with open('test.json', 'w') as fp:
    json.dump(test_datas, fp, ensure_ascii=False)
最后修改:2020 年 10 月 11 日
如果觉得我的文章对你有用,请随意赞赏