The method by which JS loops through JSON data
- 2020-03-30 03:32:38
- OfStack
JSON data such as: {" options ":" [{/ "text/" :" Wang Jiawan /, / / "value" : / 9 "/"}, {/ "text/" :" the lijiawan /, "/" value
E / 10: "/"/"}, {" text / : "/" shao house bay /, "/" value/" : / 13 "/"}] "}
Js can be written as:
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}];
for(var o in data){
alert(o);
alert(data[o]);
alert("text:"+data[o].name+" value:"+data[o].age );
}
or
<script type="text/javascript">
function text(){
var json = {"options":"[{/"text/":/" Wang Jiawan /",/"value/":/"9/"},{/"text/":/" The lijiawan /",/"value/":/"10/"},{/"text/":/" Shao house bay /",/"value/":/"13/"}]"}
json = eval(json.options)
for(var i=0; i<json.length; i++)
{
alert(json[i].text+" " + json[i].value)
}
}
</script>
PS: about json operation, here again for you to recommend a few more practical json online tools for your reference:
Online JSON code verification, verification, beautification, formatting tools:
(link: http://tools.jb51.net/code/json)
JSON online formatting tool:
(link: http://tools.jb51.net/code/jsonformat)
Online XML/JSON interconversion tool:
(link: http://tools.jb51.net/code/xmljson)
Json code online formatting/beautification/compression/editing/conversion tools:
(link: http://tools.jb51.net/code/jsoncodeformat)
Online json compression/escape tool:
(link: http://tools.jb51.net/code/json_yasuo_trans)
C language style /HTML/CSS/json code format beautification tool:
(link: http://tools.jb51.net/code/ccode_html_css_json)