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
Post a Comment