羽毛请求 WCF,JSON 中的单引号与双引号



我正在尝试使用Feathers请求框架调用WCF服务(https://github.com/request/request(Feathers请求框架使用单引号,WCF使用双引号。

{'name': 'Alice'} vs. {"name": "Alice"}

如何让 WCF 接受单引号? 或 我可以强制羽毛请求框架使用双引号吗?

对于 FeathersJS,您可以自定义快速传输 API 中记录的响应格式化程序。如果这确实是您需要的格式(根据 JSON 规范无效(,则可以在 jcoc611/cassandraMAP 上找到一个执行您想要的操作的分叉序列化程序,并通过如下内容协商用作 Feathers 格式化程序:

const cassandraMAP = require("./path/to/cassandraMap");
app.configure(express.rest(function(req, res) {
// Format the message as text/plain
res.format({
'application/json': function() {
res.json(res.data);
},
'application/wcf-myformat': function() {
res.end(cassandraMAP.stringify(res.data));
}
});  
}))

诀窍是将 JSON 对象添加到请求中传递的选项的 JSON 属性中。然后,JSON 格式正确,WCF 服务可以接受请求:)

const option = {
url:'http://..../NoteBasic.svc/json/SendMessageExecute',
method: 'POST',
json: {token: 'xxxxxxxx', message_id: 4}
};
request(option, function (err, httpResponse, body) {
console.log(httpResponse);
});

最新更新