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)
Last modification:October 11th, 2020 at 09:56 pm