json对象

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>数据获取测试页</title>
<script type="text/javascript" src="plugin/jquery/jquery-1.8.3.js"></script>
<script type="text/javascript"
	src="plugin/JUI/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript" src="plugin/table/yfTable.js"></script>
<script type="text/javascript" src="plugin/Page/jquery.pagination.js"></script>
<script type="text/javascript" src="js/common/common.js"></script>
<script type="text/javascript" src="js/data/dataSource.js"></script>
<script type="text/javascript" src="js/data/Sk.js"></script>
<script type="text/javascript" src="js/data/Net.js"></script>
<script type="text/javascript" src="js/data/Json.js"></script>
<script>
var data=" { root: [ {name:'1',value:'0'}, {name:'6101',value:'北京市'}, {name:'6102',value:'天津市'}, {name:'6103',value:'上海市'}, {name:'6104',value:'重庆市'},{name:'6105',value:'渭南市'}, {name:'6106',value:'延安市'}, {name:'6107',value:'汉中市'}, {name:'6108',value:'榆林市'}, {name:'6109',value:'安康市'}, {name:'6110',value:'商洛市'} ]}";
	var dataObj=eval("("+data+")");
	alert(dataObj);
	alert(dataObj.root.length);//输出root的子对象数量 
	$.each(dataObj.root,function(idx,item){ 
	if(idx==0){ 
	return true; 
	} 
	//输出每个root子对象的名称和值 
	alert("name:"+item.name+",value:"+item.value); 
	}) 
</script>
</head>
<body>
<input type="button" onclick='aaa()' value="获取" />
</body>
</html>

相关推荐