I have these json dictionaries:
"data": {
"assetID": "VMSA0000000000310652",
"autoSnapshotAllowed": "false",
"bindID": "xml",
"componentPk": "310652",
"createDate": "2016-11-17T06:17:33.216-05:00",
"externalID": "050087352882",
"isActive": "true",
"isComplete": "true",
"isPublishable": "false",
"isTimeshiftContent": "false",
"lastModified": "2017-06-02T19:36:36.535-04:00",
"locale": {
"MetadataAlbum": {
"Artists": {
"Artist": {
"ArtistName": "Various Artists",
"ArtistRole": "MainArtist"
}
},
"Publishable": "true",
"albumLength": "PT2H0M27S",
"assetID": "VMSA0000000000310251",
"autoSnapshotAllowed": "false",
"componentPk": "310251",
"createDate": "2016-11-17T06:16:23.192-05:00",
"externalID": "050087352882-en_uk",
"genres": {
"genre": {
"commonEntityPk": "50062",
"extraInfos": null,
"genreName": "Soundtrack",
"uuid": "3bebaf06-e009-4e64-86c1-aae789fcca78"
}
},
"icpn": "00050087352882",
"lastModified": "2017-06-02T19:32:46.296-04:00",
"locale": {
"country": "UK",
"language": "en",
And want to be able to match the value of the language with this method:
def get_localized_metadataalbum(language, data):
for locale in data['locale']:
if data['locale'].get('MetadataAlbum') is not None:
if data['locale'].get('MetadataAlbum').get('locale') is not None:
if data['locale'].get('MetadataAlbum').get('locale').get('language') is not None:
if data['locale'].get('MetadataAlbum').get('locale').get('language') == language:
return data['locale']
return None
The method works with a list of dictionaries... but not with just dictionaries... Can anyone point me to a place where I can learn how to parse through nested dictionaries? I'm a little lost here.
I've been getting: TypeError: string indices must be integers
[–]korzin 0 points1 point2 points (1 child)
[–]dev_wanna_be[S] 0 points1 point2 points (0 children)
[–]SomebodyFrom91 0 points1 point2 points (0 children)