Github API v3 JSON传递

时间:2017-02-09 12:35:21

标签: json api github

如何避免

的解析错误
curl -H 'Accept: application/vnd.github.VERSION.raw' -XPUT -g 'https://api.github.com/repos/USER/l1/contents/PATH/FILENAME.json?ref=gh-pages&access_token=57eef6413b12cb439b837b8fc4751b3291650de1' -d '{
   "message": "update from api",
   "committer": {
     "name": "USER",
     "email": "USERe@MAIL.com"
   },
   "content": "[{"a": "aaa","b": "bbb"}]",
   "sha": "c321fe9f6418053ecb87eb3cd2518a4xdfc83ebf"
   }'

答案

{
  "message": "**Problems parsing JSON**",
  "documentation_url": "https://developer.github.com/v3/repos/contents/"
}

而不是

"[{"a": "aaa","b": "bbb"}]"

我已经尝试了

"[{\"a\": \"aaa",\"b\": \"bbb\"}]"

然后我收到以下错误:

{
  "message": "**content is not valid Base64**",
  "documentation_url": "https://developer.github.com/v3/repos/contents/"
}

最佳,

1 个答案:

答案 0 :(得分:1)

如果您在错误响应中打开了the documentation的网址,则会看到内容需要Base64编码。