java对象怎么转成json数组 传到前台页面
2个回答
推荐于2018-04-23
展开全部
你会js吗,你就用Java生成一个js数组发到前台啊,或者使用js框架,eg:dwr,jquery ,reurn 一个json格式的页面 也可以。
JSONArray ja = JSONArray.fromObject(list);
out.print(ja.toString());
JSONArray ja = JSONArray.fromObject(list);
out.print(ja.toString());
展开全部
String name=request.getParameter("name");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
List list=dizhiservice.getbyname(name);
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[])list.get(i);
sb.append("{");
sb.append("\"" + "id" + ":"+"\"" + obj[0] +"\""+",");
sb.append("\"" + "name" + ":"+"\"" + obj[1] +"\""+",");
sb.append("\"" + "phone" + ":"+"\"" + obj[2] +"\""+",");
sb.append("\"" + "adrress" + ":"+"\"" + obj[3] +"\""+",");
sb.append("}");
if(i!=list.size()-1)
sb.append(",");
}
sb.append("]");
out.println(sb.toString());
System.out.println(sb.toString());
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
List list=dizhiservice.getbyname(name);
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[])list.get(i);
sb.append("{");
sb.append("\"" + "id" + ":"+"\"" + obj[0] +"\""+",");
sb.append("\"" + "name" + ":"+"\"" + obj[1] +"\""+",");
sb.append("\"" + "phone" + ":"+"\"" + obj[2] +"\""+",");
sb.append("\"" + "adrress" + ":"+"\"" + obj[3] +"\""+",");
sb.append("}");
if(i!=list.size()-1)
sb.append(",");
}
sb.append("]");
out.println(sb.toString());
System.out.println(sb.toString());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |