将 Json 转换为 Python Object(一) 发表于 2018-06-09 | 1234567891011121314151617$ cat example.py import jsonclass JSONObject: def __init__(self, dict): vars(self).update(dict)# this is valid json stringdata = '{"channel":{"lastBuild":"2013-11-12", "component":["test1", "test2"]}}'jsonobject = json.loads(data, object_hook=JSONObject)print(jsonobject.channel.component[0])print(jsonobject.channel.lastBuild) 123$ python example.pytest12013-11-12