python通过json读写序列类型的数据文件
1 import json 2 class a: 3 def writeReadJson(self): 4 list2 =['1',5.,7,'3'] 5 with open("test.txt",'w') as f: 6 json.dump(list2,f)#将列表写入f文件 7 with open("test.txt", 'r') as f1: 8 j = json.load(f1)#将f1文件内容加载并赋给j 9 print(j) #输出{'3': 6, '5': 8} 10 print(json.dumps(list2))#输出["1", 5.0, 7, "3"] 11 a().writeReadJson()