您应该这样做:
服务器端:
String json1 = new Gson().toJson(object1); String json2 = new Gson().toJson(object2); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); String bothJson = "["+json1+","+json2+"]"; //Put both objects in an array of 2 elementsresponse.getWriter().write(bothJson);
客户端:
$.getJSON("MyServlet", paramenters, function (data){ var data1=data[0], data2=data[1]; //We get both data1 and data2 from the array $("h3#name").text(data1["name"]); $("span#level").text(data1["level"]); $("span#college").text(data2["college"]); $("span#department").text(data2["department"]);});
希望这可以帮助。干杯
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)