Python读取和写入json文件

import json
with open("E://record.json","w") as f:
        s = json.loads('{"user":"22222","times":3,"datas":[{"khh":"11111","khxm": "mack"},{"khh":"22222","khxm": "jame"}]}')
        json.dump(s,f)

with open("E://record.json","r") as f:
     s = json.load(f)
     for key in s.keys():
         if key == 'datas':
            for data in s[key]:
                 for v in data.keys():
                        print data[v]
         else:
            print s[key]
把数据写入本地的record.json文件里,然后读出来,依次打印里面的value

你可能感兴趣的:(Python读取和写入json文件)