首页 > 代码库 > js解析后台传过来的json
js解析后台传过来的json
java ,action
public void print(String rs){ PrintWriter out; try { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); out = response.getWriter(); // 获取分类数据 out.print(rs); out.flush(); out.close(); } catch (IOException e) {// LogUtil.errorLog(TAG, "print", e); }}print("[{"proCode":"10241101","sellerId":"1001"},{"proCode":"10241101","sellerId":"1002"},{"proCode":"10241102","sellerId":"1001"}];")
后台拼成json格式,通过ajax接收返回结果,
$.ajax({ url : "utilAction.action", type : "GET", data : "service=showProduct", success : function(result) { var products = eval(result);// 转换为json对象 var datatable = "<table>"; for ( var i in products) { datatable = datatable + "<tr><td>" + products[i].proCode + "</td><td>" + products[i].sellerId+"</td></tr>"; } datatable = datatable + "</table>"; $("#mainDIV").html(datatable); } });
js解析后台传过来的json
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。