js解析json格式

 

 function save(){
    			var value2 = { 
			    "china":[ 
			        {"name":"hangzhou", "item":"1"}, 
			        {"name":"shanghai", "item":"2"}, 
			        {"name":"sichuan", "item":"3"} 
			    ], 
			    "America":[ 
			        {"name":"aa", "item":"12"}, 
			        {"name":"bb", "item":"2"} 
			    ], 
			    "Spain":[ 
			        {"name":"cc", "item":"1"}, 
			        {"name":"dd", "item":"23"}, 
			        {"name":"ee", "item":"3"} 
			    ] 
			}; 			
			
			for (var countryObj in value2) 
			{ 
			    document.write(countryObj + ":<br />") 
			    for (var cityObj in value2[countryObj]) 
			    { 
			        //可以用document.write("-----" + value2[countryObj][cityObj].item + "<br />"); 
			        document.write(cityObj + " ++++++ " + value2[countryObj][cityObj]["name"] + "<br />" ); 
			    } 
			}
    	}

  

posted @ 2015-05-26 10:16  雨中飞鹭  阅读(219)  评论(0编辑  收藏  举报