0

Hi I have a ajax request which returns this

[[{"totalloginhours":"11.17"}],[{"totalagents":"2"}],[{"totalapplications":"2"}]]

How do I access this string in jQuery? I don't need to loop. I tried using $.parseJSON to parse that string

var myObj2 = $.parseJSON(result2);

which returns

enter image description here

3
  • myObj2[0].totalloginhours? Commented Jul 22, 2015 at 7:51
  • @RejithRKrishnan myObj2[0].totalloginhours is undefined Sir Commented Jul 22, 2015 at 7:52
  • this does the trick myObj2[0][0]['totalloginhours'] Commented Jul 22, 2015 at 10:30

1 Answer 1

1

Foun a way to do this by

var string = '[[{"totalloginhours":"11.17"}],[{"totalagents":"2"}],[{"totalapplications":"2"}]]';

var myObj2 = $.parseJSON(string);
var obj_totalloginhours = myObj2[0];
var obj_totalagents = myObj2[1];
var obj_totalapplications= myObj2[2];

console.log(string);
console.log(obj_totalloginhours[0].totalloginhours);
console.log(obj_totalagents[0].totalagents);
console.log(obj_totalapplications[0].totalapplications);

JS Fiddle : https://jsfiddle.net/zu0x49ye/

Sign up to request clarification or add additional context in comments.

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.