<script>

var value1="{\"layer_datum\":{\"holdId\":\"dcdm\",\"val\":\"dcdm\",\"txt\":\"dcdm\"},\"jcgx\":{\"holdId\":\"jcgx\",\"val\":\"codeName\",\"txt\":\"codeName\"}}";
var value2=eval("("+value1+")");
for( var myva in value2)
{

var x=value2[myva];
for(var my in x )
{
alert("key-"+my+":-"+x[my]);
}

alert("key"+myva+";"+value2[myva])

}

</script>

json可以说是一个对象嵌套对象的数据格式,每解一层依然是一个对象,

上面实现循环读取json对象里 的数据

<script>
var xxxx = "alert(234)";
eval(xxxx);
var opts={

data1 : [
{ no : 1 , name :'aaa', age : 12, gender : 'M' , english : 76.5 , math :92 },
{ no : 2 , name :'bbb', age : 11, gender : 'F' , english : 89 , math :87 },
{ no : 3 , name :'ccc', age : 13, gender : 'F' , english : 53 , math :62 }
],
afterComplete:function(){
var param={};
param.reqData={wqid:"${param.wqid}"};
param.reqUrl="<%=contextPath%>/datumGet/geoLayerData/getGeoLayerData.do";
ajaxRequest(param,initData,failedInit);
},
loadParam:"{\"layer_datum\":{\"qkmc\":\"长庆\"},\"jcgx\":{\"jcgxId\":\"C005001\"}}",
sortOptConfig:"{\"layer_datum\":{\"holdId\":\"dcdm\",\"val\":\"dcdm\",\"txt\":\"dcdm\"},\"jcgx\":{\"holdId\":\"jcgx\",\"val\":\"codeName\",\"txt\":\"codeName\"}}"
};

//alert("name"+eval("("+opts.loadParam+")").layer_datum.qkmc)
///var name=eval("("+opts.data1+")");
//alert(name[0].no)
//alert("="+name.loadParam.layer_datum.qkmc)
var test = eval("("+opts.sortOptConfig+")");
var mengzhijun=opts;

alert("name:"+mengzhijun.data1[1].name)
alert(mengzhijun.loadParam.layer_datum.qkmc)
//alert("url:"+ny.param.reqUrl)
alert(test.layer_datum);
alert(test.layer_datum.holdId);
</script>

05-01 01:22