ajax中后台string转json

首先导入alibaba的fastJson包

后台:

String thirdPage1=prop.getProperty("thirdPage1");
String thirdPage2=prop.getProperty("thirdPage2");
Map<String,String>map=new HashMap<>();
map.put("thirdPage1", thirdPage1);
map.put("thirdPage2", thirdPage2);
String json=JSON.toJSONString(map);
pw.print(json);

前端:

<script type="text/javascript">
$(function(){
	var lanaguage1=$('input:radio:checked').val();
	$.ajax({
		dataType:"json",
 		type:"post", 
 		url : "LanguageServlet?page=firstPage",
 		success : function(result) {
 			$("#firstPage1").html(result.firstPage1);
 			$("#firstPage2").val()=result.firstPage2;
 		}
 		}); 
 });
</script>

posted on 2017-07-26 08:55  天生一对  阅读(230)  评论(0编辑  收藏  举报

导航