unable to get values from JSON converted from XML
- by Dkong
I have passed some JSON to my page via a webservice. I used JSON.NET to convert XML to JSON. The JSON output looks ok to me, but I am unable to access some of the items in the response. I am not sure why it is not working. I am using jQuery to read the response and make the webservice call. Even when I try to read the length of the array it says 'undefined'
function GetFeed(){
document.getElementById("marq").innerHTML = '';
$.ajax({
type: "POST",
url: "ticker.asmx/GetStockTicker",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var obj = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
for (var i = 0; i < obj.length; i++) {
$('#marq').html(obj[i].person);
}
}
});
}
This is a copy and paste of my response as it appeared in firebug:
{"d":"{\"?xml\":{\"@version\":\"1.0\",\"@standalone\":\"no\"},\"root\":{\"person\":[{\"@id\":\"1\",\"name\":\"Alan\",\"url\":\"http://www.google.com\"},{\"@id\":\"2\",\"name\":\"Louis\",\"url\":\"http://www.yahoo.com\"}]}}"}