Python JSON loads/dumps breaks Unicode?

前端 未结 1 1326
时光取名叫无心
时光取名叫无心 2021-02-12 15:55

Dumping a string that contains unicode characters as json produces weird unicode escape sequences:

text = \"⌂⚘いの法嫁\"
print(text) # output: ⌂⚘いの法嫁

import json
js         


        
1条回答
  •  走了就别回头了
    2021-02-12 16:52

    Call json.dumps with ensure_ascii=False:

    json_string = json.dumps(json_dict, ensure_ascii=False)
    

    On Python 2, the return value will be unicode instead of str, so you might want to encode it before doing anything else with it.

    0 讨论(0)
提交回复
热议问题