js 取出json数组中的值
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js 取出json数组中的值</title>
</head>
<body>
<script language="javascript教程">
var json={"status":1,"info":"u83b7u53d6u6210u529f","data":[{"id":"4","name":"u77f3u5bb6u5e84","information":"u5e02","Region_id":"3","type":"1"}]}
var data=json.data;
for(i=0;i<data.length;i++)
{
document.write("Name:"+data[i].name+",Info:"+data[i].information+"");
}
</script>
这里主要用for来遍历json数组值并输出
<script language="javascript">
function e()
{
var json=[{"kl_id":"2","kl_title":"Test date","kl_content":"Test date","kl_type":"1","id":"1"},{"kl_id":"2","kl_title":"Test","kl_content":"Test","kl_type":"1","id":"2"}]
var str = "";
for (var one in json)
{
for(var key in json[one])
{
str += json[one][key] + ",";
}
}
document.form.txtName.value = str;
}
</script>
<form >
<input name="txtName" >
</form>
</body>
</html>