json - How to remove unicode characters from Dictionary data in python -


after using request library , getting below dict in response.json()

{u'xyz': {u'key1': none, u'key2': u'value2'}} 

i want remove unicode characters , print key value pairs without unicode chars

i have tried below method remove , shows malformed string

>>> import json, ast >>> c = {u'xyz': {u'key1': none,u'key2': u'value2'}} >>> ast.literal_eval(json.dumps(c)) 

getting 'valueerror: malformed string'

any suggestion on how ?

you can use unicodestring.encode("ascii","replace")

>>> ustr=u'apple' >>> ustr u'apple' >>> astr=ustr.encode("ascii","replace") >>> astr 'apple' 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -