擅长:python、mysql、java
<p>这是另一个解决方案:<a href="http://tech.zarmory.com/2013/08/python-putting-dot-in-dict.html" rel="nofollow">http://tech.zarmory.com/2013/08/python-putting-dot-in-dict.html</a></p>
<pre><code>>>> d = DefaultDotDict({1: {2: 3}})
>>> d.a.b.c.d = "magic!"
>>> import json; print json.dumps(d, indent=2)
{
"a": {
"b": {
"c": {
"d": "magic!"
}
}
},
"1": {
"2": 3
}
}
>>>
</code></pre>