function parseXML(){ var name=""; var descrip=""; var xmlDoc=this.req.responseXML; var elDocRoot=xmlDoc.getElementsByTagName("planet")[0]; if (elDocRoot){ attrs=elDocRoot.attributes; name=attrs.getNamedItem("name").value; var ptype=attrs.getNamedItem("type").value; if (ptype){ descrip+="<h2>"+ptype+"</h2>"; } descrip+="<ul>"; for(var i=0;i<elDocRoot.childNodes.length;i++){ elChild=elDocRoot.childNodes[i]; if (elChild.nodeName=="info"){ descrip+="<li>"+elChild.firstChild.data+"</li>/n"; } } descrip+="</ul>"; }else{ alert("no document"); } top.showPopup(name,descrip); } function parseJSON(){ var name=""; var descrip=""; var jsonTxt=net.req.responseText; var jsonObj=eval("("+jsonTxt+")"); name=jsonObj.planet.name var ptype=jsonObj.planet.type; if (ptype){ descrip+="<h2>"+ptype+"</h2>"; } var infos=jsonObj.planet.info; descrip+="<ul>"; for(var i in infos){ descrip+="<li>"+infos[i]+"</li>/n"; } descrip+="</ul>"; top.showPopup(name,descrip); } JSON转换成javascript对象: var jsonObj=eval("("+jsonTxt+")"); {"planet": { "name": "earth", "type": "small", "info": [ "Earth is a small planet, third from the sun", "Surface coverage of water is roughly two-thirds", "Exhibits a remarkable diversity of climates and landscapes" ] }} planet.name == "earth"