【问题标题】:How to get the latest release from Github API using JSON如何使用 JSON 从 Github API 获取最新版本
【发布时间】:2021-10-20 13:25:11
【问题描述】:

是否可以从 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 文件存在问题。

【问题讨论】:

    标签: json github github-api


    【解决方案1】:

    /repos/NAME/REPO/releases 返回一个版本数组,您想用JS[0].tag_name 获取第一个版本。

    如果您只需要最新版本,请使用/repos/NAME/REPO/releases/latest 并保留JS.tag_name

    【讨论】:

      猜你喜欢
      • 2016-06-30
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 2016-04-26
      相关资源
      最近更新 更多