我试图从 python 发送一个简单的字典到一个 JSON 文件,但是我总是收到“ TypeError: 1425 is not JSON Series alable”消息。
import json
alerts = {'upper':[1425],'lower':[576],'level':[2],'datetime':['2012-08-08 15:30']}
afile = open('test.json','w')
afile.write(json.dumps(alerts,encoding='UTF-8'))
afile.close()
如果我添加默认参数,那么它会写入,但是整数值会以字符串的形式写入 json 文件,这是不可取的。
afile.write(json.dumps(alerts,encoding='UTF-8',default=str))