#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 #{u‘update_time‘: u‘12982929921‘, u‘version‘: u‘0.0.0‘, u‘desc‘: {u‘hdw‘: {u‘version‘: u‘0.0.2‘, u‘desc‘: {u‘imu‘: u‘1.0.0‘, u‘sensor‘: u‘1.0.1‘, u‘power‘: u‘1.0.0‘, u‘motor‘: u‘1.0.0‘}}, u‘soft‘: {u‘version‘: u‘0.0.1‘, u‘desc‘: {u‘web‘: u‘1.0.0‘, u‘base‘: u‘1.0.0‘, u‘server‘: u‘1.0.0‘}}}}
原文:https://www.cnblogs.com/sea-stream/p/10871077.html