如果我有如下类似的JSON:
"children": [
{
"firstName": "Alice",
"age": 6
},
{
"firstName": "Bob",
"age": 8
}
{
"firstName": "Candice",
"age": 4
}
]
我想要一个包含所有名字值的数组,我该如何用python获取它们?
我尝试过以下方法,但我的数据集较大(40000行),重复它是不切实际的:
children = JSON
firstNames = []
firstNames.append(json.loads(children.text)['children'][0]['firstName'])
firstNames.append(json.loads(children.text)['children'][1]['firstName'])
firstNames.append(json.loads(children.text)['children'][2]['firstName'])
我已经考虑过使用for循环来替换这些数字,但不知道该怎么做。