Action:
//转成JSON字符串
String jsonStr = this.listToJson(list);
//转成JSON字符串JSONArray jsonList = JSONArray.fromObject(list);String jsonStr = jsonList.toString();
//声明JSONObject
JSONObject data = new JSONObject();
//以下实现将JSON字符串传到前台
response.setContentType("text/json");
response.setCharacterEncoding("UTF-8");
PrintWriter out = null;
try {
out = response.getWriter();
data.put("size", list.size());
data.put("totalRows", totalRows);
data.put("pageCount", pageCount);
data.put("StrListContext", jsonStr);
out.println(data.toString());
} catch (IOException e) {
logger.error("FareAction:queryFareDetail" + e.getMessage());
} catch (JSONException e) {
logger.error("FareAction:queryFareDetail" + e.getMessage());
} finally {
out.flush();
out.close();
}
JS:
//查询回调函数
function doQueryActioin(data)
data.size;//size属性