json的dump和dumps的区别
dump将字典转换为json字符串并存入文件中
dumps将字典转换为json字符串
json.dump(dict, open(filename, "w"))
json.dumps(dict)
json的dump方法比dumps方法多了一个参数,也就是文件名
jsObj = json.dumps(dict)
with open(filename, "w") as f:
f.write(jsObj)
f.close()
等同于
json.dump(dict, open(filename, "w"))