python dict中将unicode打印显示为中文 博客分类: python
程序员文章站
2024-03-24 10:24:58
...
dict内容:
d = {u'status': u'BASE_ERROR', u'code': 7, u'uid': u'b660be2a-3a4d-4c40-bc1d-3c55cf7eb340', u'content': None, u'handler': u'USER', u'busiCode': u'-2', u'version': u'001', u'msg': u'\u67e5\u8be2geohash\u5468\u56f4\u53f8\u673a\u7ecf\u7eac\u5ea6\u4fe1\u606f\u5f02\u5e38com.zuche.redis.TedisConnectionException: java.net.ConnectException: Connection timed out'}
展示中文, 直接上代码:
In [165]: d = {u'status': u'BASE_ERROR', u'code': 7, u'uid': u'b660be2a-3a4d-4c40-bc1d-3c55cf7eb340', u'content': None, u'handler': u'USER', u'b ...: usiCode': u'-2', u'version': u'001', u'msg': u'\u67e5\u8be2geohash\u5468\u56f4\u53f8\u673a\u7ecf\u7eac\u5ea6\u4fe1\u606f\u5f02\u5e38co ...: m.zuche.redis.TedisConnectionException: java.net.ConnectException: Connection timed out'} In [166]: print d {u'status': u'BASE_ERROR', u'content': None, u'code': 7, u'busiCode': u'-2', u'uid': u'b660be2a-3a4d-4c40-bc1d-3c55cf7eb340', u'version': u'001', u'msg': u'\u67e5\u8be2geohash\u5468\u56f4\u53f8\u673a\u7ecf\u7eac\u5ea6\u4fe1\u606f\u5f02\u5e38com.zuche.redis.TedisConnectionException: java.net.ConnectException: Connection timed out', u'handler': u'USER'} In [167]: import json In [168]: dd = json.dumps(d).decode('unicode-escape') In [169]: print dd {"status": "BASE_ERROR", "content": null, "code": 7, "busiCode": "-2", "uid": "b660be2a-3a4d-4c40-bc1d-3c55cf7eb340", "version": "001", "msg": "查询geohash周围司机经纬度信息异常com.zuche.redis.TedisConnectionException: java.net.ConnectException: Connection timed out", "handler": "USER"}