如何循环这个json对象?

2024-04-24 10:09:56 发布

您现在位置:Python中文网/ 问答频道 /正文

api返回给我这个JSON:

'status': 200, 'result': [{'code': 'osgb4000000074565050', 'name_1': 'Durrington', 'name_1_lang': None, 'name_2': None, 'name_2_lang': None, 'local_type': 'Village', 'outcode': 'SP4', 'county_unitary': 'Wiltshire', 'county_unitary_type': 'UnitaryAuthority', 'district_borough': None, 'district_borough_type': None, 'region': 'South West', 'country': 'England', 'longitude': -1.77784130353605, 'latitude': 51.1989322399005, 'eastings': 415619, 'northings': 144436, 'min_eastings': 415126, 'min_northings': 143719, 'max_eastings': 416555, 'max_northings': 145363}, {'code': 'osgb4000000074573451', 'name_1': 'West Durrington', 'name_1_lang': None, 'name_2': None, 'name_2_lang': None, 'local_type': 'Suburban Area', 'outcode': 'BN13', 'county_unitary': 'West Sussex', 'county_unitary_type': 'County', 'district_borough': 'Worthing', 'district_borough_type': 'District', 'region': 'South East', 'country': 'England', 'longitude': -0.421810304962843, 'latitude': 50.8324879562536, 'eastings': 511236, 'northings': 104848, 'min_eastings': 510546, 'min_northings': 103835, 'max_eastings': 511721, 'max_northings': 105831}]}

我想提取“输出码”。我尝试了以下方法:

print(data.result.outcode)` and `print(data.result['outcode'])

还有这个:

for row in data:
   print(result.outcode)

以及:

for row in data:
    print(['result'][0]['outcode'])

我几乎尝试了我能想到的每一种变化。。。你知道吗


Tags: namenonelangtyperesultminmaxprint