There are so many json serializing/deserializing options, so I'm not sure which one is the correct one to use, and why there are so many options to do seemingly the same thing. I've seen JsonConvert, JsonSerializer, JavaScriptSerializer, and several others.
Looking for help on correctly deserializng a json array into a c# list of complex objects.
JQUERY:
var users = [];
for (var i = 0; i < response.length; i++)
{
var u =
{
Id: response[i].id,
UserName: response[i].username,
FirstName: response[i].first_name,
LastName: response[i].last_name
};
users[i] = u;
}
var ul = JSON.stringify({ 'userlist': users});
$.ajax({
type: "POST",
url: "/myurl/addusers",
data: { 'userlist': ul },
dataType: "json",
success: function (response) {
},
error: function (xhr, status, error) {
}
});
C# (this doesn't work):
[HttpPost]
public ActionResult AddUsers(string userlist)
{
JavaScriptSerializer ser = new JavaScriptSerializer();
var users = ser.Deserialize<List<User>>(userlist);
...
}
[Serializable]
public class User
{
public string Id { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}