How to navigate JSON Object in jQuery?

ajax, javascript, jquery, json

Solution

The value of `data` that you've logged is an object with a property named `d`, that contains a string value. You could probably make adjustments at your server side to make the value of `d` an object rather than a string, but the way it is currently constructed, you would be able to parse it into an object using `JSON.parse`.

Once you've done that, the resulting object should be an array, containing one single object. Thus, your access to `RMA_ID` would be as follows:

var data = JSON.parse(data.d);
alert(data[0].RMA_ID);

Problem

I made this webservice that handles my database functions, and this is an AJAX call to one of the methods. ``` $.ajax({ type: "POST", url: "Service/dataBaseService.asmx/getRMAData", data: '{"RMAId": 1 }', contentType: "application/json; charset=utf-8", dataType: "json", async: true, cache: false, success: function (data) { console.log(data); alert(data.RMA_ID); } }); ``` this is what is logged: ``` ({d:"[{\"RMA_ID\":1,\"RequestDate\":\"2013-02-28T00:00:00\",\"Company\":1,\"Status\":\"Accepted \",\"Serial\":201764,\"LastChangeDate\":\"2013-02-28T00:00:00\",\"LastChangeBy\":\"Foreign \",\"Price\":null}]"}) ``` However `alert(data.RMA_ID)` returns undefined aswell as `data.d.RMA_ID`? How can I get hold of the values?

Original source