JSONObject和JSONArray

需要注意的是网络传输时,需要用字符串进行传输,所以需要先将json对象用toString()转换为字符串形式,再在ajax里面用$.parseJSON转换成json对象。
JSONObject插入元素用put,JSONArray插入元素用add

$.ajax({	
	url:getBasePath()+"/ANoteServlet",
	async:true,
	cache:false,
	type:"post",
	contentType: "application/json; charset=utf-8",
	data:JSON.stringify(param1),
	success:function(msg){
		
		$("#noteUl li").css("display","none");
		var message = $.parseJSON(msg);//将json类型字符串转换为json对象				
		if(message.noteNum==0)
		{	
			$("#4notes").css("display","none");				
			$("#latestNote").append("<h5>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;暂无笔记&nbsp;&nbsp;您可以选择<a href='/fileManagement/personalPage/add-note.jsp'>创建笔记</a></h5>");
		}else 
		{
			for(i=0;i<message.noteNum;i++)
			{	
				$("#noteUl").children("li").eq(i).css("display","block");
				$("#noteUl").children("li").eq(i).find("a").html(message.noteList[i]);
				$("#noteUl").children("li").eq(i).children("div").eq(0).children("span").eq(1).html(message.courseNameOfNoteList[i]);
				$("#noteUl").children("li").eq(i).children("div").eq(1).html(message.createTimeOfNoteList[i]);  								
			}					
		}
	
	},
	error:function(response,status){		
	console.log(status);					
	}				
});	
CourseDao courseDao = new CourseDao();
 JSONArray jsonArray = new JSONArray();	
 JSONArray noteNumList = new JSONArray();
 JSONArray folderNumList = new JSONArray();
 List<Course> courseList = (List<Course>)courseDao.find2LatestCourse(currentUser.getUserId());
 for(int i = 0;i<courseList.size();i++){
	 jsonArray.add(courseList.get(i).getName());
	 noteNumList.add(courseList.get(i).getNoteNum());
	 folderNumList.add(courseList.get(i).getFolderNum());
	  
 }
 o.put("courseNum", courseList.size());
 o.put("courseList", jsonArray);
 o.put("noteNumList", noteNumList);
 o.put("folderNumList", folderNumList);
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-17 14:38
干个蛋,干不了一点!!!!我真服了,还没搞完,很急。&nbsp;今天ddl,活没干完直接通宵,刺激。食堂很好吃,感觉离职的时候会胖10斤。mt喜欢能直接干活的,没空指导我,很难受。每个人都是笑嘻嘻的,但是从他们聊天中都能感受到各种试探,我有点慌了大家真的nb,都能准时完成工作下班,我羡慕啊!!!!!每天好累,想离职了💔
牛客26106072...:能去字节实习说明你的能力挺被认可的,实习中的这种累更有利于个人职场成长,试着当熬夜打游戏一样熬一熬,实习的意义就是看自己的差距和适应能力,总比等到工作时各种不适应辞职要好得多吧?
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-15 17:32
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务