Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Extract value from JSONArray in Javascript

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 182
    Comment on it

    Hello Guys,

    I will explain that how to extract values from JSONArray String in Javascript.

    For example we have this jsonarray string below:

    1. var jsonarraystr ='[{
    2. "city": "Jaipur",
    3. "state": "Rajasthan",
    4.  
    5. },
    6. {
    7. "city": "Ahmedabad",
    8. "state": "Gujrat",
    9.  
    10. },
    11. {
    12. "city": "Delhi",
    13. "state": "New Delhi",
    14.  
    15. }]';

    jsonarraystr is javascript variable which have JsonArray String.

    Now, we extract values from jsonarraystr variable using below javascript code :

    1. var jsonarray = JSON.parse(jsonarraystr);
    2.  
    3. for(var i=0;i< jsonarray.length;i++)
    4. {
    5. var city = jsonarray[i].city;
    6. var state = jsonarray[i].state;
    7. }

    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: