Home > DeveloperSection > Forums > Extracting data from JSON in javascript
Ida B Wells
Ida B Wells

Total Post:30

Points:210
Posted on    June-20-2013 3:30 AM

 JSON JSON 
Ratings:


 1 Reply(s)
 1645  View(s)
Rate this:
Hi Developers,

This is my JSON that I get back (this is what it is after I stringify it):

{"1":"Water Accumulation","2":"Water Preservation","3":"Release Target Date"}
How can I extract this data in javascript. I have tried eval, JSON.parse both do not work.

Thanks in advance for any recommendations or solutions.


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-20-2013 7:52 AM

Hi,

I couldn't find any problem, but you can try as following

var a = '{"1":"Water Accumulation","2":"Water Preservation","3":"Release Target Date"}';

var b = JSON.parse(a);

console.log(b);
console.log(b[1]);
console.log(b[2]);
console.log(b[3]);
Or you can just do

var b = {"1":"Water Accumulation","2":"Water Preservation","3":"Release Target Date"};

    console.log(b[1]);
    console.log(b[2]);
    console.log(b[3]);

Don't want to miss updates? Please click the below button!

Follow MindStick