JavaWeb 에서 Ajax 가 JSon 형식 에 대한 분석
{ "people": [
  { "firstName": "Brett", "lastName":"McLaughlin", "email": "111111" },
  { "firstName": "Jason", "lastName":"Hunter", "email": "22222" },
  { "firstName": "Elliotte", "lastName":"Harold", "email": "33333" }
]}{ "programmers": [
  { "firstName": "Brett", "lastName":"McLaughlin", "email": "3333" },
  { "firstName": "Jason", "lastName":"Hunter", "email": "1222" },
  { "firstName": "Elliotte", "lastName":"Harold", "email": "3333" }
 ],
"authors": [
  { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
  { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
  { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
 ],
"musicians": [
  { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
  { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
 ]
}$.ajax({
url:"          ",
data:{"id":id}, //  /     
async : false,
dataType : "json",
success : function(data) {
alert("firstName = " + data.firstName);
}
});response.setCharacterEncoding("utf-8");
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = null;
		String count = "{ "firstName": "Brett" }
;
		try {
			out = response.getWriter();
		} catch (Exception e) {
			e.printStackTrace();
		}
		out.print(count);
		out.flush();{
  { "firstName": "Brett", "lastName":"McLaughlin", "email": "111111" },
  { "firstName": "Jason", "lastName":"Hunter", "email": "22222" },
  { "firstName": "Elliotte", "lastName":"Harold", "email": "33333" }
}$.ajax({
url:"          ",
data:{"id":id}, //  /     
async : false,
dataType : "json",
success : function(data) {
for(int i = 0; i < data.length; i++) { //        Json  
     var datas = data[i];
     alert(datas.firstName);
     alert(datas.lastName);
     alert(datas.email);
}
}
});{ "programmers": [
  { "firstName": "Brett", "lastName":"McLaughlin", "email": "3333" },
  { "firstName": "Jason", "lastName":"Hunter", "email": "1222" },
  { "firstName": "Elliotte", "lastName":"Harold", "email": "3333" }
 ],
"authors": [
  { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
  { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
  { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
 ],
"musicians": [
  { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
  { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
 ]
}$.ajax({
url:"          ",
data:{"id":id}, //  /     
async : false,
dataType : "json",
success : function(data) {
var pro = data.programmers; // pro programmers     
for(int i = 0; i < pro.length; i++) { //        Json  
     var datas = pro[i];
     alert(pro.firstName);
     alert(pro.lastName);
     alert(pro.email);
}
var aut = data.authors; // aut authors     
for(int i = 0; i < aut.length; i++) { //        Json  
     var datas = aut[i];
     alert(aut.firstName);
     alert(aut.lastName);
     alert(aut.genre);
}
var mus = data.musicians; // aut authors     
for(int i = 0; i < mus.length; i++) { //        Json  
     var datas = mus[i];
     alert(mus.firstName);
     alert(mus.lastName);
     alert(mus.instrument);
}
}
});5.
{ "listaccountsresponse" : { "count":1 ,"account" : [ {"id":5,"name":"xian1","accounttype":0,"domainid" :2,"domain":"Server","receivedbytes":649444,"sentbytes":175467975,"vmlimit":"20","vmtotal":2,"vmavailable" :"18","iplimit":"20","iptotal":1,"ipavailable":"19","volumelimit":"20","volumetotal":2,"volumeavailable" :"18","snapshotlimit":"20","snapshottotal":0,"snapshotavailable":"20","templatelimit":"20","templatetotal" :0,"templateavailable":"20","vmstopped":0,"vmrunning":2,"state":"enabled","user":[{"id":5,"username" :"xian1","firstname":"Eric","lastname":"Tang","email":"[email protected]","created":"2012-03-22T09 :36:44+0800","state":"enabled","account":"xian1","accounttype":0,"domainid":2,"domain":"Server","timezone" :"Asia/Shanghai"}]} ] } }
$.ajax({
url:"          ",
data:{"id":id}, //  /     
async : false,
dataType : "json",
success : function(data) {
var accounts = data.listaccountsresponse.account; //  “account”    
for(int i = 0; i < accounts.length; i++) { //        Json  
     var datas = accounts[i];
     alert(datas.id);
     alert(datas.name);
     alert(datas.accounttype);
     ..........
}
}
});여 기 는 자신 이 쓴 백 스테이지 패스 입 니 다.
@RequestMapping(value="/applyVm/listApplyVmCount", method={RequestMethod.GET, RequestMethod.POST})
	public void listApplyVmCount(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = null;
		String count = "";
		try {
			out = response.getWriter();
			Map map = applyVmService.findApplyVmCount();
			Gson gson = new Gson();
			count = gson.toJson(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		out.print(count);
		out.flush();
	}  본문 참고:http://xiaoxiong-it.iteye.com/blog/1485121
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【intra-mart】Java 클래스 파일 등이 Import 할 수 없게되었을 때의 대처법오늘은, intra-mart로 Java의 클래스 파일등이 Import 할 수 없게 되었을 때의 대처법을 기재합니다. JavaEE 개발을 할 때 자신도 같은 상황이 되었습니다. 비망을 위해 기사로하고 있습니다. 【전제...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.