python - How can I loop through this json object?
问题描述
An api return gives me this 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}]}
I want to extract the "outcode". I have tried the following:
print(data.result.outcode)` and `print(data.result['outcode'])
and this:
for row in data:
print(result.outcode)
and:
for row in data:
print(['result'][0]['outcode'])
I have pretty much tried every variation that I can think of...
解决方案
推荐阅读
- neo4j - 我们可以使密码字段查询不区分大小写吗
- python - 使用基于内部最低值的 pandas 数据框对数据集进行排序
- powershell - 如何重定向或检索由 Powershell 脚本运行的 telnet 进程的输出?
- java - 如何修复 java play 框架中自签名 TLS 证书的“unknown_certificate”错误
- r - 如何强制 predict() 预测固定数量的值
- angular - 在订阅方法中设置时变量未在模板中更新
- x86 - ZombieLoad 的微架构根本原因是什么?
- python - 作为两个子流程的中介的 subprocess.PIPE 何时关闭?
- javascript - Angular 7 - 如何将 HTTP 请求与 observable 链接起来
- set - momentJS 链接 setter .year().day() 返回错误的日期