How to get string objects instead of Unicode from JSON?

前端 未结 21 892
伪装坚强ぢ
伪装坚强ぢ 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:15

    I had a JSON dict as a string. The keys and values were unicode objects like in the following example:

    myStringDict = "{u'key':u'value'}"
    

    I could use the byteify function suggested above by converting the string to a dict object using ast.literal_eval(myStringDict).

提交回复
热议问题