查看: 52|回复: 0

github、gitee获取 json 方法

[复制链接]

2

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2012-5-20
发表于 2022-8-4 09:53:00 | 显示全部楼层 |阅读模式

github、gitee获取 json 方法

github 获取 json

第一种方式 raw.githubusercontent.com

使用 raw.githubusercontent.com,去掉 blob

github提供的读取资源文件格式如下:

https://raw.githubusercontent.com/${owner}/${repo}/${Branch}/${path}

比如:

github 仓库文件路径:

https://github.com/username/project/blob/master/test.json

获取原始数据路径:

https://raw.githubusercontent.com/username/project/master/test.json

这种方式在国内的访问速度不是很理想,如果可以,请选择以下其他方式。

第二种方式 api.github.com

第二种方式,请求接口时,需要添加额外的 headers 信息,而且有次数限制,未验证的客户端每小时只能请求60次。

https://api.github.com/repos/${username}/${repo}/contents/${apth}?ref=${branch}

headers: {
  Accept: 'application/vnd.github.v3.raw',
}

这种方式在国内的访问速度比第一种好。

第三种方式

使用 github 的 github pages 功能,将 json 文件部署到上面,在国内的访问速度也还可以,具体部署方式请参考官方文档。

gitee 获取 json 方式

gitee 获取 json 的方式更简单一些。

只需要将 gitee 仓库路径的 blob 修改为 raw 即可。

如:

原始仓库路径:

https://gitee.com/username/project/blob/master/data.json

获取原始数据的路径:

https://gitee.com/username/project/raw/master/data.json

国内用户推荐使用 gitee。



来源:https://www.cnblogs.com/lzhida/p/16549603.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部