定义字典并直接输出,结果输出结果中文是乱码展示
d={'name':'lily','age':18,'sex':'女','no':1121} print d
输出结果:
{'age': 18, 'no': 1121, 'name': 'lily', 'sex': '\xe5\xa5\xb3'}
解决方法:
d={'name':'lily','age':18,'sex':'女','no':1121} print json.dumps(d,encoding='utf-8',ensure_ascii=False)
输出结果:
{"age": 18, "no": 1121, "name": "lily", "sex": "女"}
更多Python知识请关注