开发者

Tuple<string, int> JSON to pass to wcf

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.

H开发者_如何学运维ere 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);


That won't work because Tuples don't have a default (no-argument) constructor.

Although simply changing wcf to expect an object with two properties such as Item1 and Item2 will work.

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:

var data = { Item1: 5, Item2: "test" };

... while you'd be far less likely to write:

var data = { Title: 5, ID: "test" };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜