How to get Json values ​​using Jquery

advertisements

Hi I'm new to Jquery and i don't know how to use json data. I have a Json which is coming as a response. My success function is

success: function(resp)
{
    var x = JSON.stringify(resp);
    alert(x);

}

alert is having following JSON

{"xyz":{"abc":[{"action":"fail","result":"xxx"},{"action":"pass","resut":"yyy"}]}}

I want action value alone. How can i get this value from x variable and how can i utilize this value in HTML. Thanks in advance.


When you use JSON.stringify() you are turning it into a string, you want it as an object to access the data. Try this:

success: function(resp) {
    alert(resp.xyz.abc[0].action);
    var x = resp.xyz.abc[0].action  // to use the value in html later on
}

If it is returned as a string (I can't tell at this point), you can turn it into an object (as long as it is valid JSON) by using $.parseJSON()