Ajax&Json<3>Json
Json 引入 JSON:JavaScript 对象表示法(JavaScript Object Notation) 。
Json格式语法 JSON 对象 <script type="text/javascript"> function loadInfo(){ var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4 && xmlHttp.status==200){ //alert(xmlHttp.responseText); var dataObj=eval("("+xmlHttp.responseText+")"); /* alert(dataObj.name); alert(dataObj.age); */ document.getElementById("name").value=dataObj.name; document.getElementById("age").value=dataObj.age; } }; xmlHttp.open("get","getAjaxInfo",true); xmlHttp.send(); } Json 第三方 jar 包引入 Json-lib //String resultJson="{"name":"张三","age":22}"; JSONObject resultJson=new JSONObject(); resultJson.put("name","张三"); resultJson.put("age",22); out.print(resultJson);从上面代码可看出 简洁了很多 很方便!!jar包是利用面对对象的思想来编程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |