相关疑难解决方法(0)

如何完整遍历未知深度的复杂字典?

从中导入JSON可以获得非常复杂和嵌套的结构.例如:

{u'body': [{u'declarations': [{u'id': {u'name': u'i',
                                       u'type': u'Identifier'},
                               u'init': {u'type': u'Literal', u'value': 2},
                               u'type': u'VariableDeclarator'}],
            u'kind': u'var',
            u'type': u'VariableDeclaration'},
           {u'declarations': [{u'id': {u'name': u'j',
                                       u'type': u'Identifier'},
                               u'init': {u'type': u'Literal', u'value': 4},
                               u'type': u'VariableDeclarator'}],
            u'kind': u'var',
            u'type': u'VariableDeclaration'},
           {u'declarations': [{u'id': {u'name': u'answer',
                                       u'type': u'Identifier'},
                               u'init': {u'left': {u'name': u'i',
                                                   u'type': u'Identifier'},
                                         u'operator': u'*',
                                         u'right': {u'name': u'j',
                                                    u'type': u'Identifier'},
                                         u'type': u'BinaryExpression'},
                               u'type': u'VariableDeclarator'}],
            u'kind': u'var',
            u'type': u'VariableDeclaration'}],
 u'type': u'Program'}
Run Code Online (Sandbox Code Playgroud)

如上所述,走复杂结构的推荐方法是什么?

除了一些列表,主要是字典,结构可以变得更加重叠,所以我需要一个通用的解决方案.

python json dictionary python-2.7

46
推荐指数
7
解决办法
5万
查看次数

标签 统计

dictionary ×1

json ×1

python ×1

python-2.7 ×1