How does jQuery deserialize JSON?

I am using jQuery.ajax (...) to retrieve JSON data from ASP.NET MVC service. When the server encounters an exception, I send the 400 Bad Request status to the client and send my exception as JsonResult:

Response.StatusCode = 400;
return Json(new { ex.Message, ex.StackTrace });

And here is my jQuery code:

$.ajax(
{
    type: "POST",
    url: deleteUrl,
    dataType: "json",
    data:
    {
        dataItems: dataItems,
        toJSON: true
    },
    success: function(msg)
    {
        alert(msg[i].dataItem);
    },
    error: function(request, status, error)
    {
        alert(request.responseText);
    }
});

My ASP.NET code sends me to the error section of my JavaScript code, and the error block allows me to read request.responseText, rather than working with objects returned from the server.

Now, instead of adding another JavaScript, include something like json_parse and just deserialize your exception, I would like to just use the same JSON parser that jQuery uses, although I cannot find it easily to find.

Can someone point me in the right direction?

+5
3

jQuery eval, . 1.4, JSON, (, Firefox)

+6

, javascript, json-, eval , :

var myObject = eval('(' + myJSONtext + ')');

http://www.json.org/js.html

+2

Perhaps this may help you. I use it to remove comments and spaces in my json:

json = eval( o.responseText
    .replace( /\/\*(.*)\*\/g, ' ' )
    .replace( /([^\:])\/\/[^\n]*\n/g, '$1' )
    .replace( /^\s|\s+|\s$/g, '' ) )
0
source

All Articles