now I have some data as below:
{"parameters":{"fields":["a","b","c"]}
and I use ajax to send the request to .net WebMethod like below:
$.ajax({
url: 'Query/Query.asmx/test2?nocache=1',
dataType: "json",
data: JSON.stringify(data),
type: 'POST',
contentType: "application/json; charset=utf-8",
})
and the WebMethod I used in query.asmx is:
[WebMethod]
public string test2(Dictionary<string, object> parameters)
{
return "ok";
}
we can see that the parameters["fields"] is of type System.Object[]
But now I have a requirement to compress the data and decompress it in backend, and the data becomes a string(after decompressed). Now I want to deserialize it to exact the same type as before.
after decompression, the data becomes a JSON string:
"{\"parameters\":{\"fields\":[\"a\",\"b\",\"c\"]}}"
Now I want to use JavaScriptSerializer to deserialize it to the same type. But What I can get is parameters["fields"] of type System.Collections.ArrayList and not the type System.Object[] I require.
the code is like below
public class TestDataObject
{
public Dictionary<string, object> parameters { get; set; }
}
-
var serializer = new JavaScriptSerializer();
var a = serializer.Deserialize<TestDataObject>(d);
So the question is: is there a way for me to deserialize it to exactly the same type? I can't use another library since I have got some javascriptSerializer converters implemented for some customized types.