如何遍历此json对象?

时间:2019-07-19 16:35:39

标签: python json

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'])

我已经尝试了所有我能想到的变化...

0 个答案:

没有答案