元组JSON传递给wcf
任何人都知道如何通过 Json 传递它。
尝试做类似的事情
var data = { Item1: "test", Item2: 5 };
var JSONdata = $.toJSON(data);
但是没有用。尽管只需更改 wcf 以期望具有两个属性(例如 Item1 和 Item2)的对象就可以了。
这是在 asp.net 中,
提前致谢。
这是我正在使用的示例...我将对其进行一些修剪以使其更易于阅读:
function Post(data, url)
{
$.ajax({
type: 'POST',
url: url,
data: data,
success: function(return){},
dataType: 'json'
});
}
var data = { Item1: "test", Item2: 5 };
var JSONdata = $.toJSON(data);
Post(data, url);
Anyone know how to pass this via Json.
Tried doing something like
var data = { Item1: "test", Item2: 5 };
var JSONdata = $.toJSON(data);
However that did not work. Although simply changing wcf to expect an object with two properties such as Item1 and Item2 will work.
This is in asp.net
Thanks in advance.
Here is example I'm using... I'll trim it a bit to make it easier to read:
function Post(data, url)
{
$.ajax({
type: 'POST',
url: url,
data: data,
success: function(return){},
dataType: 'json'
});
}
var data = { Item1: "test", Item2: 5 };
var JSONdata = $.toJSON(data);
Post(data, url);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是行不通的,因为元组没有默认(无参数)构造函数。
我强烈建议这样做。定义数据传输对象类是一种很好的做法。它将允许您更清楚地命名您的属性,这使事情更容易维护并减少引入错误的可能性。例如,很容易不小心写成:
...而你不太可能写成:
That won't work because Tuples don't have a default (no-argument) constructor.
I strongly suggest doing this. Having a defined Data Transfer Object class is good practice. It will allow you to name your properties more clearly, which makes things easier to maintain and reduces the likelihood of introducing bugs. For example, it'd be really easy to accidentally write:
... while you'd be far less likely to write: