Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save njujerry/c3f7f399b1d193b0eb72e1d1f4bfe560 to your computer and use it in GitHub Desktop.
Save njujerry/c3f7f399b1d193b0eb72e1d1f4bfe560 to your computer and use it in GitHub Desktop.
Python中将json-loads后的unicode转换为str
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