Json.dump failing with 'must be unicode, not str' TypeError

前端 未结 3 941
我在风中等你
我在风中等你 2021-02-05 10:10

I have a json file which happens to have a multitude of Chinese and Japanese (and other language) characters. I\'m loading it into my python 2.7 script using io.open

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 10:22

    Can you try the following?

    with io.open("testJson.json",'w',encoding="utf-8") as outfile:
      outfile.write(unicode(json.dumps(cards, ensure_ascii=False)))
    

提交回复
热议问题