In MVC, we have the
JsonResult
class by which we can return back data in JSON format. Below is a simple sample code which returns back a Customer
object in JSON format using JsonResult
.public JsonResult getCustomer() { Customer obj = new Customer(); obj.CustomerCode = "1001"; obj.CustomerName = "Shiv"; return Json(obj,JsonRequestBehavior.AllowGet); }
Below is the JSON output of the above code if you invoke the action via the browser.