首页 > 代码库 > python字典中显示中文

python字典中显示中文

#coding=utf-8
import json
dict={‘title‘:"这是中文"}
print json.dumps(dict,ensure_ascii=False,encoding="utf-8")

 

 

books=[
{‘name‘:u‘C#从入门到精通‘,‘price‘:23.7,‘store‘:u‘卓越‘},
{‘name‘:u‘C#从入门到精通二‘,‘price‘:44.5,‘store‘:u‘当当‘},
{‘name‘:u‘C#从入门到精通三‘,‘price‘:25.7,‘store‘:u‘新华书店‘},
{‘name‘:u‘C#从入门到精通四‘,‘price‘:25.8,‘store‘:u‘新华书店‘},
]
store=[]
for item in books:
for p in item:
if p==‘store‘:
store.append(item[p])
print json.dumps(store, ensure_ascii=False, encoding="utf-8")

 

["卓越", "当当", "新华书店", "新华书店"]

python字典中显示中文