我已经解决了!
感谢@stack链接到 Accessing dict keys like an attribute? 有两种不同的方法来解决我的问题:
json.Test3['Test4']
使用类:
class AttributeDict(dict): def __getattr__(self, attr): return self[attr] def __setattr__(self, attr, value): self[attr] = value
顺便说一下,我发现第一种方法更简单。
我现在可以访问 Test4 就像这样:
Test4
print(json.Test3['Test4'])