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

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

sample code:

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


        
12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 00:21

    As of Python 3.7 the following code works fine:

    from json import dumps
    result = {"symbol": "ƒ"}
    json_string = dumps(result, sort_keys=True, indent=2, ensure_ascii=False)
    print(json_string)
    
    

    Output:

    {"symbol": "ƒ"}
    

提交回复
热议问题