Thursday, 5 September 2013

JSON string that contains double quotes for a value is being sent to the controller as NULL

JSON string that contains double quotes for a value is being sent to the
controller as NULL

I make this AJAX call:
function CreateProjectTree(sc)
{
debugger;
$.ajax({
type: "POST",
url: "../api/projects/SearchProjects",
data: sc,
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function(data)
{
buildTree(data);
}).fail(function(jqXHR, status, error)
{
console.log("Error: " + error);
});
}
If the variable sc does not have any double quotes for any of the values,
(e.g. "Person": "Jack"), it works fine.
However, if the object contains double quotes as such: "Person": ""Jack"",
it'll send the object as NULL to the controller.
I'm not sure why this is happening.
Do I have to do anything special in this case?

No comments:

Post a Comment