如何在不同的{}和[](使用Python)中获取相应的json数据?

如何在不同的{}和[](使用Python)中获取相应的json数据?,python,json,Python,Json,我正在尝试使用Python Flask处理JSON数据。 以下是我的数据: [ { 'className': 'BoardGame', 'fields': { 'objectId': {'type': 'String'}, 'playerName': {'type': 'String'}, 'cheatMode': {'type': 'Boolean'}, 'sco

我正在尝试使用Python Flask处理JSON数据。
以下是我的数据:

[
    {   'className': 'BoardGame', 
        'fields': {
            'objectId': {'type': 'String'}, 
            'playerName': {'type': 'String'}, 
            'cheatMode': {'type': 'Boolean'}, 
            'score': {'type': 'Number'}, 
            'updatedAt': {'type': 'Date'}, 
            'createdAt': {'type': 'Date'}
        }, 
        'classLevelPermissions': {
            'addField': {'*': True}, 
            'create': {'*': True}, 'get': {'*': True}, 
            'update': {'*': True}, 'find': {'*': True}, 
            'delete': {'*': True}
        }
    }, 
    {   'className': 'RPGGAme', 
        'fields': {
            'objectId': {'type': 'String'}, 
            'GameId': {'type': 'String'}, 
            'robotName': {'type': 'String'}, 
            'updatedAt': {'type': 'Date'}, 
            'createdAt': {'type': 'Date'}
        }, 
        'classLevelPermissions': {
            'addField': {'*': True}, 
            'create': {'*': True}, 'get': {'*': True}, 
            'fields': {'*': True}, 'find': {'*': True}, 
            'delete': {'*': True}
        }
    }
]
问题是由于
[]
{}
的复杂格式,我无法获取相应的数据

这是我想要的:

[0]["className"]: "BoardGame" <---String
[0]["fields"]: ["objectId","playerName","cheatMode"....] <-- List Of String
[1]["className"]: "RPGGame"    <---String
[1]["fields"]: ["objectId","GameId",....]   <-- List Of String
但是,它只能找到特殊键的值,但无法设置范围(我所说的范围是第一个“
{}
”作为数组0+第二个“
{}
”作为数组1+classLevelPermissions中的“字段”不会涉及到结果,从某种意义上说,我猜是深度级别)。我仍然无法解决问题并得到我想要的

如何设置深度并放入相应的数组,例如[0]、[1]

data = [
    {   'className': 'BoardGame', 
        'fields': {
            'objectId': {'type': 'String'}, 
            'playerName': {'type': 'String'}, 
            'cheatMode': {'type': 'Boolean'}, 
            'score': {'type': 'Number'}, 
            'updatedAt': {'type': 'Date'}, 
            'createdAt': {'type': 'Date'}
        }, 
        'classLevelPermissions': {
            'addField': {'*': True}, 
            'create': {'*': True}, 'get': {'*': True}, 
            'update': {'*': True}, 'find': {'*': True}, 
            'delete': {'*': True}
        }
    }, 
    {   'className': 'RPGGAme', 
        'fields': {
            'objectId': {'type': 'String'}, 
            'GameId': {'type': 'String'}, 
            'robotName': {'type': 'String'}, 
            'updatedAt': {'type': 'Date'}, 
            'createdAt': {'type': 'Date'}
        }, 
        'classLevelPermissions': {
            'addField': {'*': True}, 
            'create': {'*': True}, 'get': {'*': True}, 
            'fields': {'*': True}, 'find': {'*': True}, 
            'delete': {'*': True}
        }
    }
]
试试这个:

oput = {}
for idx, dict in enumerate(data):
    oput[idx] = {}
    oput[idx]["className"] = dict["className"]
    oput[idx]["fields"] = dict["fields"].keys()
然后:

oput = {}
for idx, dict in enumerate(data):
    oput[idx] = {}
    oput[idx]["className"] = dict["className"]
    oput[idx]["fields"] = dict["fields"].keys()
oput[0]["className"]
>> 'BoardGame'

oput[0]["fields"]
>>  ['objectId', 'playerName', 'cheatMode', 'score', 'updatedAt', 'createdAt']

oput[1]["className"]
>> 'RPGGAme'

oput[1]["fields"]
>> ['robotName', 'GameId', 'createdAt', 'objectId', 'updatedAt']