1

How to parse the following JSON Array using javascript??

4
  • If that's a real username and password, you should probably remove them. Commented Oct 8, 2012 at 9:58
  • Updated code below. You don't need to parse url variable. It's already parsed by jQuery because of setting dataType: 'json'. Commented Oct 8, 2012 at 10:08
  • you can use eval(), like this: var obj = eval("(" + myjson + ")"); Commented Oct 16, 2012 at 4:31
  • @ijse You can, but you shouldn't. Commented Oct 16, 2012 at 5:10

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Try alert(url.Data[0].agentid) ? Maybe you should use console.log(url) for debugging?
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.