python提取按要求筛选的内容_根据Python中的特定条件筛选
获取的JSON数据
我是python新⼿,正在尝试使⽤urllib从musicbrainz获取JSON数据,并且能够解析⼀些数据。但是,对于某些艺术家来说,JSON数据中的某些字段/键并不存在,因为它们可能不是必需的。我不确定如何根据进⼀步的筛选条件过滤获取的JSON数据。在
在下⾯的⽰例中,我只需要为release list>;>release>;>release group>;类型为“Single”的JSON数据过滤。获取的JSON 每次可以有多达50次的迭代,但是我只提供feed以进⼀步过滤类别为“Single”的那些。请告诉我⼀个⼈该怎么做。谢谢!在
JSON⽰例:{
"created": "2012-12-27T13:22:55.834Z",
"recording-list": {
"count": 3,
"offset": 0,
"recording": [{
"score": "100",
"title": "Stronger",
"artist-credit": {
"name-credit": [{
"artist": {
"name": "Britney Spears",
"sort-name": "Spears, Britney"
}
}]
},
"release-list": {
"release": [{
"id": "13c5511f-1f99-4ffe-97d5-562c05e9d8d5",
"title": "Hit Hammer 2001 (disc 1)",
"status": "Official",
"artist-credit": {
"name-credit": [{
"artist": {
"id": "89ad4ac3-39f7-470e-963a-56509c546377",
"name": "Various Artists"
}
}]
},
"release-group": {
"id": "6c4c2cc3-3d8e-3a19-9d46-da076c34b6e9", "type": "Compilation",
"primary-type": "Album",
"secondary-type-list": {
"secondary-type": ["Compilation"]
}
},
"medium-list": {
"track-count": 20,
"medium": [{
"position": 1,
"track-list": {
"count": 20,
"offset": 0,
"track": [{
"number": "1",
"title": "Stronger",
"length": 203266
}]
}
}]
}
}]
}
}, {
"id": "feb9acbf-1d3d-4395-9512-bfbdcfa72eb9", "score": "100",
"title": "Stronger",
"artist-credit": {
"name-credit": [{
"joinphrase": "",
"artist": {
"name": "Britney Spears",
"sort-name": "Spears, Britney"
}
}]
},
"release-list": {
"release": [{
"id": "45e2a271-2f6b-4029-b11e-b6d94d169f9a", "title": "Stronger: The Remixes",
"status": "Official",
"release-group": {
"id": "4d018ba8-f05e-4817-8c70-34307161a0fc", "type": "Single",
"primary-type": "Single"python怎么读取json文件
},
"date": "2000-12-12",
"country": "US",
"medium-list": {
"track-count": 6,
"medium": [{
"position": 1,
"format": "CD",
"track-list": {
"count": 6,
"offset": 0,
"track": [{
"number": "1",
"title": "Stronger",
"length": 203000
}]
}
}]
}
}]
},
"puid-list": {
"puid": [{
"id": "28550845-c68a-314d-90c1-010dff730f4a" }]
}
}]
}
}
Python代码:
^{pr2}$

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。