json.dumps在默認狀況下,對於非ascii字符生成的是相對應的字符編碼,而非原始字符json
例如:app
>>> import json
>>> js = json.loads('{"haha": "哈哈"}')
>>> print json.dumps(js)
{"name": "\u54c8\u54c8"}測試
解決辦法很簡單:編碼
>>> print json.dumps(js, ensure_ascii=False)
{"name": "哈哈"} spa
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,)