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

testing - Detect whether test has failed within fixture -

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

android - Create single AAR file from multiple modules using Gradle -