As far as I can tell, I am getting a parser error because some of the data I am returning contains apostrophes.
Error I'm getting:
SyntaxError: Unexpected end of input at Object.parse (native) at jQuery.parseJSON...
My javascript:
var viewModel = kendo.observable({
hospitalDataSource: new kendo.data.DataSource({
transport: {
read: {
url: "/Hospital/GetHospitals",
dataType: "json",
type: "GET"
},
schema: {
model: {
id: "Id",
fields: {
ProviderId: { type: "number" },
Name: { type: "string" },
Active: { type: "string" }
}
}
},
errors: "errorMsg"
},
pageSize: 10,
error: function (e) {
toastr.options = {
"positionClass": "toast-bottom-full-width"
};
toastr.error('There was an error:' + e.errors, 'Uh Oh!');
this.cancelChanges();
},
serverPaging: false,
serverFiltering: false,
serverSorting: false
}),
})
Controller JsonResult:
[HttpGet]
public JsonResult GetHospitals()
{
var hospitals = hospitalService.GetAllHospitals();
return Json(hospitals, JsonRequestBehavior.AllowGet);
}
As I mentioned above, I believe I'm getting the parser error because some of my data contains apostrophes.
For example, Name
might include the string Women and Children's Hospital
I'm still new to MVC/C# and Json so I'm not sure how to go about solving this. Is there a way to escape all of the apostrophes? Or is there something else I should be doing.
Let me know if anything I said is not clear. Thanks!