首页 > Web开发 > 详细

json 文件读写

时间:2019-05-15 18:07:54      阅读:102      评论:0      收藏:0      [点我收藏+]

 

#coding=utf-8
import json
data ={"update_time":"12982929921","version":"0.0.0","desc":{"hdw":{"desc":{"power":"1.0.0","motor":"1.0.0","imu":"1.0.0","sensor":"1.0.1"},"version":"0.0.2"},"soft":{"desc":{"web":"1.0.0","server":"1.0.0","base":"1.0.0"},"version":"0.0.1"}}}

#写入
with open(tmp.json, w) as f:
    json.dump(data, f)
try:
    with open(tmp.json, r) as f:
        k=json.load(f)
        print(k)
except ValueError:
        print("empty!")

#output
#{uupdate_time: u12982929921, uversion: u0.0.0, udesc: {uhdw: {uversion: u0.0.2, udesc: {uimu: u1.0.0, usensor: u1.0.1, upower: u1.0.0, umotor: u1.0.0}}, usoft: {uversion: u0.0.1, udesc: {uweb: u1.0.0, ubase: u1.0.0, userver: u1.0.0}}}}

 

json 文件读写

原文:https://www.cnblogs.com/sea-stream/p/10871077.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!