Ying Style Ying Style - 2 years ago 150
Javascript Question

How could I parse this json-string?

I have a string:

[{"data1":"A"},{"data2":"B"},{"data3":"C"}]


I used jQuery to convert this string to json:

test_json = $.parseJSON('[{"data1":"A"},{"data2":"B"},{"data3":"C"}]');


I got 3 objects:

enter image description here

I don't know, how could i get the key and value in this string-json?
Or the format of string-json is wrong?

Answer Source

have you tried cycle thorough the parsed array?

var test_json = $.parseJSON('[{"data1":"A"},{"data2":"B"},{"data3":"C"}]');

for(var a=0;a<test_json.length;a++) {
    var obj = test_json[a];
    for(var idx in obj) {
      console.log(idx, obj[idx]);
    }
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download