我有一个这样的班级:
class Payload(object):
def __init__(self, payload__):
self.__dict__ = json.loads(payload__)
我可以这样读取JSON有效负载:
json = Payload('{"Test1":"Test2","Test3":{"Test4":true}}')
所以我可以获得
Test
就像这样:
print(json.Test1) # result: Test2
但我无法获得
Test4
它是
Test3
print(json.Test3.Test4) #result: AttributeError: 'dict' object has no attribute 'Test4'
所以,错误是
AttributeError: 'dict' object has no attribute 'Test4'
任何帮助都将不胜感激。
谢谢!