如何使用 JSON 从 Github API 获取最新版本
How to get the latest release from Github API using JSON
我已尝试从 github 获取最新版本。我想我可能读错了数组。我在这里做错了什么?
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var JS = JSON.parse(this.responseText);
console.log(JS.tag_name)
}
};
xmlhttp.open("GET", "https://api.github.com/repos/NAME/REPO/releases", true);
xmlhttp.send();
随着控制台的响应:
undefined
我是 JSON 的新手,所以我对如何读取数组有点困惑。
/repos/NAME/REPO/releases
returns 一系列版本,你想获得第一个 JS[0].tag_name
.
如果您只需要最新版本,请使用 /repos/NAME/REPO/releases/latest
并保留 JS.tag_name
。
我已尝试从 github 获取最新版本。我想我可能读错了数组。我在这里做错了什么?
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var JS = JSON.parse(this.responseText);
console.log(JS.tag_name)
}
};
xmlhttp.open("GET", "https://api.github.com/repos/NAME/REPO/releases", true);
xmlhttp.send();
随着控制台的响应:
undefined
我是 JSON 的新手,所以我对如何读取数组有点困惑。
/repos/NAME/REPO/releases
returns 一系列版本,你想获得第一个 JS[0].tag_name
.
如果您只需要最新版本,请使用 /repos/NAME/REPO/releases/latest
并保留 JS.tag_name
。