Saving utf-8 texts in json.dumps as UTF8, not as \u escape sequence

前端 未结 12 927
说谎
说谎 2020-11-21 23:25

sample code:

>>> import json
>>> json_string = json.dumps(\"ברי צקלה\")
>>> print json_string
\"\\u05d1\\u05e8\\u05d9 \\u05e6\\u05         


        
12条回答
  •  -上瘾入骨i
    2020-11-22 00:08

    Use codecs if possible,

    with codecs.open('file_path', 'a+', 'utf-8') as fp:
        fp.write(json.dumps(res, ensure_ascii=False))
    

提交回复
热议问题