Im having more difficulty with this than I should be!
Im trying to extract postalCode from the below bing maps JSON:
{
"authenticationResultCode":"ValidCredentials",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2014 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets":[
{
"estimatedTotal":1,
"resources":[
{
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
"bbox":[
56.216052482429326,
-2.9494141659354827,
56.223777917570679,
-2.9308900340645176
],
"name":"Street, Leven, KY8 5",
"point":{
"type":"Point",
"coordinates":[
56.2199152,
-2.9401521
]
},
"address":{
"addressLine":"Street",
"adminDistrict":"Scotland",
"adminDistrict2":"Fife",
"countryRegion":"United Kingdom",
"formattedAddress":"Street, Leven, KY8 5",
"locality":"Leven",
"postalCode":"KY8 5"
},
"confidence":"Medium",
"entityType":"Address",
"geocodePoints":[
{
"type":"Point",
"coordinates":[
56.2199152,
-2.9401521
],
"calculationMethod":"Interpolation",
"usageTypes":[
"Display",
"Route"
]
}
],
"matchCodes":[
"Good"
]
}
]
}
],
"statusCode":200,
"statusDescription":"OK",
"traceId":"8fdd75362a694e02a45fa17d6e7c0e95|DB40080932|02.00.108.1000|DB4SCH010061257, DB4SCH010061346"
}
My code only returns the field names and not the attribute:
r = requests.get(current_url)
json_data = r.json()
for item in json_data['resourceSets'][0]['resources']:
for field in item['address']:
print field
What am I missing? Sorry for the novice question!
print field, item['address'][field]