Python2.7 将字典转json格式入库
Python2.7 将字典转json格式入库
1、代码示例:
import json developer = { "name": "admin", "salary": 9000, "skills": ["Raspberry pi", "Machine Learning", "Web Development"], "email": "admin@webkaka.com" } with open("developerPrettyPrint.json", "w") as write_file: # json.dump(developerPrettyPrint, write_file) json.dump(developer, write_file, indent=4, separators=(", ", ": "), sort_keys=True) print("Done writing pretty printed JSON data into a file")
2、输出结果