我猜我错过了一些傻事,所以我提前道歉。
我正在尝试在模拟模式下运行以下网址中找到的示例: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}}"
}
任何想法都会很棒!
答案 0 :(得分:0)
您需要发送类似res.json({});
答案 1 :(得分:0)
以json对象发送不会对结果对象进行字符串化,
var result = {name:"asdf",id:1212}
res.json(result);