Python 如何请求json数据

Python 如何请求json数据,python,request,Python,Request,我有Json数据。我想请求URL。但我只能看到内容数据。如何请求Url JSON数据: { "totalElements": 3143, "totalPages": 158, "page": 0, "size": 20, "content": [{ "approved": false, "images": [{ "url": "http://example.com/imageurl.jpg"

我有Json数据。我想请求URL。但我只能看到内容数据。如何请求Url

JSON数据:

{
"totalElements": 3143,
"totalPages": 158,
"page": 0,
"size": 20,
"content": [{
            "approved": false,
            "images": [{
                "url": "http://example.com/imageurl.jpg"
            }]
        }
Python代码:

import requests
import json
supplierIdInputValue = 12345 #Enter supId
url = "http://example.com/requestdataurl" + str(supplierIdInputValue) + "&size=100"
headers = {
    'content-type': "application/json"
}
response = requests.request("GET", url, headers=headers)
spmdata = json.loads(response.text)
for spmdata in spmdata["content"]:
    images = str(spmdata["images"])
    print(images)

如果我正确理解了你的问题,你可能会在解码回答时遇到问题。您可以尝试对响应调用的
json()
方法,请参见
response=requests.request(“GET”,url,headers=headers)

在上面的行之后,请尝试:

j = response.json()

for c in j['content']:
    for i in c['images']:
        print(i['url'])

也许这对你有用。此外,您似乎正在手动构造URL查询字符串,但是如果您将Python字典作为参数为
params
参数,则
requests
库可以为您解决此问题。

欢迎使用堆栈溢出。不幸的是,我不明白你的问题。请阅读有关有效提问的提示。这里到底出了什么问题?什么是响应。文本是响应的格式。我可以看到[{'url':'}],但我只需要。此数据位于图像标签中。我使用这个代码,但不工作。代码:对于图像[“url”]:link=str(图像[“url”])打印(链接)感谢您的工作。必须手动更改参数。因为我们对所有供应商都有不同的数据