json.dumps在默认情况下,对于非ascii字符生成的是相对应的字符编码,而非原始字符
例如:
>>> import json
>>> js = json.loads('{"haha": "哈哈"}')
>>> print json.dumps(js)
{"name": "u54c8u54c8"}
解决办法很简单:
>>> print json.dumps(js, ensure_ascii=False)
{"name": "哈哈"}
import json #将字典转换成json文本 dic = {"companyId":95651, "positionName":"自动化测试", "workYear":"3-5年", "education":"本科", "jobNature":"全职", "companyLogo":"i/image2/M01/2C/57/CgoB5lzUGO2AAoc3AACv6egD568191.png", "salary":"15k-25k", "city":"北京", "financeStage":"B轮", "industryField":"社交", "companyShortName":"玩吧", "approve":1, "positionId":5537531, "createTime":"2019-07-26 10:53:22", "positionAdvantage":"七险一金,弹性不打卡,免费午餐,季度旅游", "companySize":"150-500人"} print(type(dic)) aString = json.dumps(dic,ensure_ascii=False) print(type(aString)) print(aString) json.dump(dic,open('test2.json',mode='w',encoding='utf-8'),ensure_ascii=False,)