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

asked Jul 22, 2015 at 7:46
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/

answered Jul 22, 2015 at 8:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.