I'm using asp.net page that is fully ajaxified (with jquery lib) and calling another asp.net callback page to get/post data to server. Some users of my page experiencing following error when serializing json object
there was an error deserializing the object of the type ... object type ... contains invalid utf8 bytes
$.ajax({
type: "POST",
async: false,
url: 'AjaxCallbacks.aspx?Action=' + actionCode,
data: {
objectToSerialize: JSON.stringify(obj, null, 2)
},
dataType: "json",
success: function(operationResult) {
//handle success
},
error: function(xhttp, textStatus, errorThrown) {
//handle error
}
});
to deal with this I've added "contentType" option ...
$.ajax({
type: "POST",
async: false,
url: 'AjaxCallbacks.aspx?Action=' + actionCode,
data: {
objectToSerialize: JSON.stringify(obj, null, 2)
},
contentType: 'application/json; charset=utf-8', //<-- added to deal with deserializing error
dataType: "json",
success: function(operationResult) {
//handle success
},
error: function(xhttp, textStatus, errorThrown) {
//handle error
}
});
but now I can not read this object on server side as I could before:
string objectJson = Request.Params["objectToSerialize"].ToString();
I got following error: "Object reference not set to an instance of an object."
Any ideas?