0

How to parse following json object

{ "info": [ { "systemIp": "192.168.1.1", "status": "done 956" }, { "systemIp": "192.153.1.1", "status": "done" } ] }

In Javascript or jQuery can anybody help?

Output should be like

systemIp 192.168.1.1

status done

systemIp 192.153.1.1

status done
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
srihari
  • 917
  • 4
  • 14
  • 26

3 Answers3

1

Use this

            <script type="text/javascript">
    var abc =  { "info": [ { "systemIp": "192.168.1.1", "status": "done 956" }, { "systemIp": "192.153.1.1", "status": "done" } ] };

            $.each(abc.info,function(i,val){
                alert("systemIp : "+val.systemIp);
                alert("status : " +val.status);
            });

            /*  other way ot iterate */

           $.each(abc.info,function(i,outer){
                $.each(outer,function(j,inner){
                  alert(j+" : "+inner);
                });
            });
    </script>
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
1

This is not very efficient way, but this will serve your purpose

var a ={ "info": [ { "systemIp": "192.168.1.1", "status": "done 956" }, 
         { "systemIp": "192.153.1.1", "status": "done" } ] }

    var objL = a['info']
    for(var i = 0;i<objL.length;i++){
      for(keys in objL[i]){
        console.log( keys + ' ' +objL[i][keys])  
      }
    }

Example

brk
  • 48,835
  • 10
  • 56
  • 78
0

With JavaScript: JSON.parse()

With jQuery: jQuery.parseJSON()

Tuan Ha
  • 620
  • 2
  • 8
  • 25
  • using for loop how to iterate values – srihari Feb 11 '16 at 06:31
  • @srihari with jQuery, you can use [`$.each()`](http://api.jquery.com/each/). With JavaScript: json.info.forEach(function(value, index) { console.log(value); }) – Tuan Ha Feb 11 '16 at 06:34
  • $.each(result.info, function(v,k){ v // value k // k is stand for key or index }) – Rana Ahmer Yasin Feb 11 '16 at 06:42
  • @srihari: It seems you would gain the most from reading a tutorial about JavaScript basics: http://eloquentjavascript.net/02_program_structure.html#h_oupMC+5FKN, http://eloquentjavascript.net/04_data.html . This is pretty fundamental stuff. – Felix Kling Feb 11 '16 at 06:46