擅长:python、mysql、java
<p>您可以使用instanceof()方法检查某个内容是否是dict,如果为true,则可以让代码迭代该dict。在这种情况下,我将执行递归。在</p>
<pre><code>def read_dict(some_dictionary):
for key, value in some_dictionary:
if isinstance(value, dict):
# if value is another dict, iterate through the key,value pairs in value
read_dict(value)
elif isinstance(value, list):
# if value is a list, add your own code to iterate through a list
pass
else:
#not a dict, do what you needed to do eg:
print 'value of %s is %s' % (key, value)
read_dict(the_dict_object)
</code></pre>