Feathers 请求 WCF,JSON 中的单引号与双引号
Feathers request WCF, single quotes vs double quotes in JSON
我正在尝试使用 Feathers 请求框架调用 WCF 服务 (https://github.com/request/request)Feathers 请求框架在 WCF 使用双引号的地方使用单引号。
{'name': 'Alice'} vs. {"name": "Alice"}
如何让 WCF 接受单引号?
要么
我可以强制 Feathers 请求框架使用双引号吗?
对于 FeathersJS,您可以像这样自定义响应格式化程序as documented in the Express transport API. If that is really the format you need (which is invalid according to the JSON specification), a forked serializer that does what you want can be found at jcoc611/cassandraMAP and used as a Feathers formatter through content negotiation:
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);
});
我正在尝试使用 Feathers 请求框架调用 WCF 服务 (https://github.com/request/request)Feathers 请求框架在 WCF 使用双引号的地方使用单引号。
{'name': 'Alice'} vs. {"name": "Alice"}
如何让 WCF 接受单引号? 要么 我可以强制 Feathers 请求框架使用双引号吗?
对于 FeathersJS,您可以像这样自定义响应格式化程序as documented in the Express transport API. If that is really the format you need (which is invalid according to the JSON specification), a forked serializer that does what you want can be found at jcoc611/cassandraMAP and used as a Feathers formatter through content negotiation:
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);
});