js中获取json的值:
例:
<!doctype html>
<html>
<head>
<title>HTML5 test</title>
<meta charset="UTF-8" />
</head>
<body>
<script>
var tmp = {"name":"value"}
<!-- tmp.key和tmp["key"]均可获取value值。-->
alert(tmp.key);
alert(tmp["key"]);
</script>
</body>
</html>
若tmp中有很多键值对,可以通过for循环来获取value值。
例:
<!doctype html>
<html>
<head>
<title>HTML5 test</title>
<meta charset="UTF-8" />
</head>
<body>
<script>
var tmp = {"name1":"value1",
"name2":"value2",
"name3":"value3",
"name4":"value4",
"name5":"value5"
}
for(var i in tmp){
alert("key:" + i + ",value:" + tmp[i]);
}
</script>
</body>
</html>