I am struggling with the deserialization of an object that has two properties. One property is a simple string, while the other property is an array of arrays, with each element in an array having a name and a value.
The POST operation works fine until it reaches the server side. I can debug on the server side, but I am unable to deserialize the passed data correctly. I am attempting to deserialize the someData object to a RequestObject on the server side.
I would appreciate your advice on this as I have been spending hours trying to solve this issue.
On the client side: (JavaScript)
var dataArrays = [];
dataArrays[0] = [ {"name":"key","value":"xyz"} ];
dataArrays[1] = [ {"name":"firstname","value":"john"}, {"name":"lastname","value":"doe"} ];
var someData = {
someKey: "xyz",
dataArrays: dataArrays
};
$.ajax({
type: 'POST',
url: './mywebservice.asmx/Test',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(someData), ..);
On the server side: (C#)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test(string someKey, string dataArrays)
{
// someKey has the value: "xyz"
// dataArrays is a string in the following format:
// [[{"name":"key","value":"xyz"}],[{"name":"firstname","value":"john"}{"name":"lastname","value":"doe"}]]
//unable to deserialize in here in any way
// ?? RequestObject requestObj = JsonConvert.DeserializeObject<RequestObject> ??
}
[DataContract]
public class StringData
{
[DataMember]
public string name { get; set; }
[DataMember]
public string value { get; set; }
}
[DataContract]
public class RequestObject
{
[DataMember]
public string someKey { get; set; }
[DataMember]
public List<StringData[]> dataArrays{ get; set; }
}