python 读写json数据

#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!")

原文地址:https://www.cnblogs.com/sea-stream/p/11063567.html