Is there an easy way to populate my C# Object with the JSON object passed via AJAX?
//This is the JSON Object passed to C# WEBMETHOD from the page using JSON.stringify
{
"user": {
"name": "asdf",
"teamname": "b",
"email": "c",
"players": ["1", "2"]
}
}
//C# WebMetod That receives the JSON Object
[WebMethod]
public static void SaveTeam(Object user)
{
}
//C# Class that represents the object structure of JSON Object passed in to the WebMethod
public class User
{
public string name { get; set; }
public string teamname { get; set; }
public string email { get; set; }
public Array players { get; set; }
}
JavaScript Serializer: requires
using System.Web.Script.Serialization;
Data Contract Serializer: requires
using System.Runtime.Serialization.Json;
- The generic type T should be serializable more on Data Contract