How to parse the following JSON Array using javascript??
2 Answers
Your code for parsing JSON with jQuery is valid and should work:
var Data = $.parseJSON('{"Status":"True","Data":[{"Loginstatus":"Success","agentid":1004}]}');
Now you can iterate through array using jQuery.each:
$.each(Data.Data, function(index, item) {
alert(item.agentid);
});
And if you want to parse data from AJAX you don't need $.parseJSON. It' already parsed:
alert(url.Data);
1 Comment
Inferpse
Try
alert(url.Data[0].agentid) ? Maybe you should use console.log(url) for debugging?I usually use the JSON lib for JavaScript: https://github.com/douglascrockford/JSON-js Just download json2.js and include in your page, then call JSON.parse like following:
var text = '{"Status":"True","Data":[{"Loginstatus":"Success","agentid":1004}]}';
var myObject = JSON.parse(text);
urlvariable. It's already parsed by jQuery because of settingdataType: 'json'.eval(), like this:var obj = eval("(" + myjson + ")");