Search code examples
ajaxjsonjqueryjquery-1.5

How can I get this value out of my json result?


I am using jquery and I am return a json result from my asp.net mvc controller.

It comes back like this

{"Errors":{"key1":"afkafk"},"IsValid":false,"SuccessMessage":""}

how do I get the value of "key1"?

I tried to do

var ajax = $.ajax({...});
ajax.success(function(response)
{
   alert(response.Errors.key1);
});

this however just prints out [object,Object]


Solution

  • That should be right.

    This implies that that is in fact not how the JSON comes back at all. Stringify response to find out for sure: alert(JSON.stringify(response));.