简体   繁体   English

如何获得 JSON 请求但获得其中的某个部分?

[英]How do I get a JSON request but get a certain part of it?

I have this current Python code...我有这个当前的 Python 代码...

import requests
import json
response = json.loads(requests.get("https://meta.multimc.org/v1/net.minecraftforge/index.json").text)

But I can't find out how to get a specific bit instead of the whole JSON page.但我不知道如何获取特定位而不是整个 JSON 页面。

I'd like to get versions.version on that URL but I can't find out what piece of code to add to make it do that.我想在 URL 上获取versions.version,但我不知道要添加什么代码才能做到这一点。

You iterate over the versions array in response['versions'] and add each version to a list.您在response['versions']中迭代版本数组并将每个版本添加到列表中。

import request
import json

response = json.loads(requests.get("https://meta.multimc.org/v1/net.minecraftforge/index.json").text)

versions=[]
for i in range(len(response['versions'])):
    versions.append(response['versions'][i]['version'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM