后台返回json对象,前台取出属性

		response.setContentType("text/html;charset=UTF-8"); 
		Map map = new HashMap();
		map.put("name", "testname");
		
		String json = JSONObject.fromObject(map).toString();
		response.getWriter().write(json.toString());
		response.getWriter().flush();
		response.getWriter().close();
		return null;

上面是后台返回的json对象,在前台取出name的值。

$.post("../../strtgcObjctvs.do","ope=init",function(data){

var json = eval("("+data+")"); // data的值是json字符串,这行把字符串转成object
        alert(json.name);// 取出属性值testname

}

借鉴的别人的  以后方便自己查看 

 文章出自:https://blog.csdn.net/abaloneking/article/details/17221683

感谢 !!!

猜你喜欢

转载自blog.csdn.net/weixin_41276058/article/details/80646470
今日推荐