I have the following graph of objects, and I use JQuery $ .Ajax () to send this identical View object in JSON (gated) from the browser to the page method on ASP.Net. JAvascript deserialization works for all rows and int in the View class, but My List<DataItem>
empty.
What I tried: using the chrome dev tools, I took a lowercase JSON, created a unit test and used both DataContractJsonSerializer
and JavaScriptSerializer
. The DataContractJsonSerializer
object has deserialized my object graph correctly, but the JavaScriptSerializer
dumped my list. How can I get the correct deserialization of my page method?
public class View { public string Text { get; set; } public string AnotherText { get; set; } public Int SomeInt { get; set; } public List<DataItem> { get; set; } } public class DataItem { public Person person {get;set} } public class Person { public int Age {get;set} } var dataa = {mqvm: mqvmJSON }; $.ajax({ type: "POST", dataType: "json", contentType: "application/json; charset=utf-8", data: JSON.stringify( dataa ), url: "GoHere.aspx/WebMethodName", success: function(data) { alert(data.d); }, error: function(jqXHR, textStatus, errorThrown) { alert(jqXHR.responseText + ' ' + errorThrown); } });
Instead (representing obj as a parameter).
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] [WebMethod] public static string CreateResponseReview(View mqvm) { return "Success"; }
how can i get this? (string parameter)
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] [WebMethod] public static string CreateResponseReview(string mqvm) {
My JSON looks like this.
{ "Text": "6", "AnotherText":"wow" "SomeInt": 5, "DataItem":[ { "person":{ "Age":23 } }, { "person":{ "Age":42 } } ] }
source share