当我想保存我的JSON时,它会添加反斜杠和双引号。单引号被双引号取代并加上斜杠
'{"created_at":"foo","created_by":"foo"}'
所以当我打开保存的文件时它看起来是这样的
"{"created_at":"foo","created_by":"foo"}"
我需要像这样
{"created_at":"foo","created_by":"foo"}
我的代码是这样的:保存
with open('data3.json', 'w', encoding='utf-8') as f:
json.dump(data3, f, ensure_ascii=False)
用以下代码保存:
import json
test = {"created_at":"foo","created_by":"foo"}
with open('data3.json', 'w', encoding='utf-8') as f:
json.dump(test, f, ensure_ascii=False)
得到以下结果:{"created_at": "foo", "created_by": "foo"}
试着编辑你的notepad++设置,也许是关于它们的显示。