Created
May 19, 2017 01:40
-
-
Save njujerry/c3f7f399b1d193b0eb72e1d1f4bfe560 to your computer and use it in GitHub Desktop.
Python中将json-loads后的unicode转换为str
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/956867/how-to-get-string-objects-instead-of-unicode-ones-from-json-in-python | |
def byteify(input): | |
if isinstance(input, dict): | |
return {byteify(key): byteify(value) | |
for key, value in input.iteritems()} | |
elif isinstance(input, list): | |
return [byteify(element) for element in input] | |
elif isinstance(input, unicode): | |
return input.encode('utf-8') | |
else: | |
return input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment