Python2 写入带有中文的数据到json文件出错:
Json.dump failing with 'must be unicode, not str' TypeError
with io.open("test.json",'w',encoding="utf-8") as outfile:
json.dump(cards, outfile, ensure_ascii=False)
解决:
# -*- coding:utf-8 -*-
import codecs
with codecs.open("test.json","w") as file:
json.dump(my_list, file, indent=4, ensure_ascii=False)