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 don't know, how could i get the key and value in this string-json? Or the format of string-json is wrong?
It has parsed the JSON correctly and returned an array of objects. You could do the following to access the first item containing { data1: "A" }
:
console.log(tessst[0])
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.