With JSON.NET I can serialize a generic list into a JSON string:
return Json(new { success = true, data = JsonConvert.SerializeObject(units) });
but how can I serialize a generic list into JSON objects. This would have the advantage that I do not need this on client side:
var jsonData = $.parseJSON(units);
Don’t serialize a part of the object, serialize the entire object:
The built-in
Jsonmethod is hard-coded to return a result that uses the built-in (somewhat limited) .NET JavaScript serializer. If you want to get something as easy to use as that, add your own “Json” method into your base controller class that does the same thing with Json.NET.