从JSON对象获取所有值,并使用Python存储在平面数组中
我正在从请求调用返回一个JSON对象。我希望从中获取所有值,并将它们存储在平面数组中 我的JSON对象:从JSON对象获取所有值,并使用Python存储在平面数组中,python,json,Python,Json,我正在从请求调用返回一个JSON对象。我希望从中获取所有值,并将它们存储在平面数组中 我的JSON对象: [ { "link": "https://f.com/1" }, { "link": "https://f.com/2" }, { "link": "https://f.com/3" } ] 我想将其存储为: [https://f.com/things/1, https://f.com/thin
[
{
"link": "https://f.com/1"
},
{
"link": "https://f.com/2"
},
{
"link": "https://f.com/3"
}
]
我想将其存储为:
[https://f.com/things/1, https://f.com/things/2, https://f.com/things/3]
我的代码如下。。它只是将每个链接打印出来:
import requests
import json
def start_urls_data():
url = 'http://106309.n.com:3000/api/v1/product_urls?q%5Bcompany_in%5D%5B%5D=F'
headers = {'X-Api-Key': '1', 'Content-Type': 'application/json'}
r = requests.get(url, headers=headers)
start_urls_data = json.loads(r.content)
for i in start_urls_data:
print i['link']
您可以使用一个简单的列表:
data = [
{
"link": "https://f.com/1"
},
{
"link": "https://f.com/2"
},
{
"link": "https://f.com/3"
}
]
print([x["link"] for x in data])
该代码只是在列表数据中循环,并将键链接的值从dict元素放入一个新列表中