我希望访问此 json 文件中图像的 URL。然而我在巢里只能走这么远。我得到的图像打印出'“url”://images....'
{
"devices": [
{
"variants":
[
{
"iMEIPrefix": null,
{
"totalTax": 0,
},
"smartTab": {
"payOffPeriod": 24,
"requiredUpfrontPayment": 0,
},
"pricingForUi": {
"payOffPeriod": 24,
"requiredUpfrontPayment": 0,
},
"memory": "64GB",
"phoneImages": [
{
"url": "//images.ctfassets.net/7bx5buq4osbe/4tfPcjBNmnbWupJ7byONiZ/0f27dc736403c4027bbf13f184ffd4fc/PIXEL3A-BLACK-FRONT.png",
"title": "PIXEL3A-BLACK-FRONT",
"description": null
},
{
"url": "//images.ctfassets.net/7bx5buq4osbe/1UVKkXIBCUPkKJ8ROvFkOO/8f25b2c57bfd774792dfb69ed1d3cc29/PIXEL3A-BLACK-SIDE.png",
"title": "PIXEL3A-BLACK-SIDE",
"description": null
},
{
"url": "//images.ctfassets.net/7bx5buq4osbe/1K2AP67ZhWb9pBtIp3r1sj/755bdc263d4a6e43e8275bea2beb92d3/PIXEL3A-BLACK-BACK.png",
"title": "PIXEL3A-BLACK-BACK",
"description": null
}
],
到目前为止我的代码
phoneImages = phone['variants'][0]['phoneImages']
data['image'] = phoneImages
例如我希望有这样的输出:
"image": [
"https://xpressphone-backend.herokuapp.com/Apple iPhone XR/xr-black-front.png",
"https://xpressphone-backend.herokuapp.com/Apple iPhone XR/xr-black-back.png"
],
最佳答案
urls = []
phoneImages = phone['variants'][0]['phoneImages']
for phoneImage in phoneImages:
urls.append = phoneImage['url']
关于python - 如何访问相互嵌套的多层字典和列表并将它们收集到一个列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56503735/