【问题标题】:apigee 127 - JSON is escaped when ran in mock modeapigee 127 - 在模拟模式下运行时 JSON 被转义
【发布时间】:2016-06-13 16:13:22
【问题描述】:

我猜我错过了一些愚蠢的事情,所以我提前道歉。

我正在尝试以模拟模式运行在以下 URL 中找到的示例:https://github.com/apigee-127/a127-samples/blob/master/weather-basic/api/swagger/swagger.yaml

JSON 响应看起来像是被转义了,导致响应验证器失败:

{
  "message": "Response validation failed: invalid content type (text/plain).  These are valid: application/json",
  "failedValidation": true,
  "originalResponse": "{\"base\":\"Sample text\",\"clouds\":{\"all\":1},\"cod\":1,\"coord\":{\"lat\":1,\"lon\":1},\"dt\":1,\"id\":1,\"main\":{\"humidity\":1,\"pressure\":1,\"temp_max\":1,\"temp_min\":1,\"temp\":1},\"name\":\"Sample text\",\"sys\":{\"country\":\"Sample text\",\"id\":1,\"message\":1,\"sunrise\":1,\"sunset\":1,\"type\":1},\"weather\":[{\"description\":\"Sample text\",\"icon\":\"Sample text\",\"id\":1,\"main\":\"Sample text\"}],\"wind\":{\"deg\":1,\"speed\":1}}"
}

任何想法都会很棒!

【问题讨论】:

    标签: json apigee127


    【解决方案1】:

    你需要发送这样的东西res.json({});

    【讨论】:

      【解决方案2】:

      作为 json 对象发送,不要对结果对象进行字符串化,

      var result = {name:"asdf",id:1212}
      res.json(result);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-31
        • 2013-08-28
        • 2014-01-28
        • 2022-01-25
        • 2015-01-27
        • 2014-11-03
        • 2019-04-19
        相关资源
        最近更新 更多