我遇到了一个返回 JSON 数据的 Gist https://gist.githubusercontent.com/rdsubhas/ed77e9547d989dabe061/raw/6d7775eaacd9beba826e0541ba391c0da3933878/gnc-js-api
我试图创建一个返回 JSON 数据的结果是这样的 https://gist.github.com/vigneshvdm/862ec5a97bbbe2021b79
我怎样才能像第一个那样创建一个链接并让它以 JSON 格式返回数据
最佳答案
问题是 HTTP 响应类型是 text/plain
但您需要 application/json
以便大多数客户端正确处理它。
更新:使用 rawgit.com 我能够让您的测试使用正确的内容类型。
我的 RawGit 网址: https://rawgit.com/anonymous/85dbc2c71023f24c2e26/raw/849848a71a1805a314897f9fe98eb7dc43e2e9b9/gistfile1.json
使用 HTTP GET,发送:
GET https://rawgit.com/anonymous/85dbc2c71023f24c2e26/raw/849848a71a1805a314897f9fe98eb7dc43e2e9b9/gistfile1.json HTTP/1.1
Accept: application/json
Host: rawgit.com
接收返回:
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 24 Dec 2014 10:57:07 GMT
Content-Type: application/json
Connection: keep-alive
X-Content-Type-Options: nosniff
X-Robots-Tag: none
RawGit-Naughtiness: 0
Access-Control-Allow-Origin: *
ETag: "0250189db62d31523a5cd0da47449eb4"
Cache-Control: max-age=300
Vary: Accept-Encoding
RawGit-Cache-Status: HIT
Content-Length: 104
[{ Name: "Vignesh", Salary: 30000 },{ Name: "Yuvraj", Salary: 90000 },{ Name: "Nithya", Salary: 87000 }]
还有几张截图:
关于git - 如何在github中创建一个返回json数据的 Gist ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27635355/