kinvey端点请求jsonparse问题

时间:2013-12-02 09:53:07

标签: json parsing rest post kinvey

任何使用kinvey控制台的人 - 我试图通过API控制台向自定义端点发出简单的帖子请求但是得到jsonParse错误。

enpoint代码是 -

 function onRequest(request, response, modules){
    modules.logger.info(request.body.name + " has " + request.body.eyes + " eyes.");
    response.complete(200);
}

请求

POST https://baas.kinvey.com/rpc/kid_TVdEjbOoXi/custom/test HTTP/1.1
Authorization: "xxx" //my authorization number
X-Kinvey-API-Version: 3
Content-Type: application/json

{
  "name": "Fred Jones",
  "eyes": "Blue"
}

回复

HTTP/1.1 400
Content-Type: application/json
X-Kinvey-Request-Id: "XXX" // the request id
X-Powered-By: Express

{
  "error": "JSONParseError",
  "description": "Unable to parse the JSON in the request",
  "debug": "Unexpected token a"
}

任何人都知道这是什么问题?

1 个答案:

答案 0 :(得分:1)

我是Kinvey的工程师,可以帮助你。

尝试将Content-Type标头值包装在引号中,以便将其解析为字符串:

POST https://baas.kinvey.com/rpc/kid_TVdEjbOoXi/custom/test HTTP/1.1
Authorization: "xxx" //my authorization number
X-Kinvey-API-Version: 3
Content-Type: "application/json"    <---- note the addition of "

{
  "name": "Fred Jones",
  "eyes": "Blue"
}