EXTRACTING DATA FROM JSON IN JAVASCRIPT

Ida B Wells

Total Post:30

Points:210
Posted by  Ida B Wells
JSON 
 2179  View(s)
Ratings:
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.
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Extracting data from JSON in javascript

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!