How to get string objects instead of Unicode from JSON?

前端 未结 21 1104
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 14:43

I\'m using Python 2 to parse JSON from ASCII encoded text files.

When loading these files with either json or simplejson, all my

21条回答
  •  野性不改
    2020-11-22 15:12

    With Python 3.6, sometimes I still run into this problem. For example, when getting response from a REST API and loading the response text to JSON, I still get the unicode strings. Found a simple solution using json.dumps().

    response_message = json.loads(json.dumps(response.text))
    print(response_message)
    

提交回复
热议问题