我们的app本身是要有联网功能的,那么我们要从网站上先获取到对应的json数据:
web服务器端servlet代码如下:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); response.setHeader("Access-Control-Allow-Origin", "*"); dao dao=new dao(); infoV[] p=dao.seekallV(); PrintWriter out=response.getWriter(); int i=0; response.setContentType("text/html;charset=UTF-8"); response.setHeader("content-type","text/html;charset=UTF-8"); out.print("["); for(i=0;p[i].getId()!=null;i++) { out.print("{"); out.print(""id":""+p[i].getId()+"","); out.print(""name":""+p[i].getName()+"","); out.print(""status":""+p[i].getStatus()+"", "); out.print(""symptom":""+p[i].getSymptom()+"", "); out.print(""level":""+p[i].getLevel()+"", "); out.print(""vcode":""+p[i].getVcode()+"""); out.print("}"); if(p[i+1].getId()!=null) {out.print(",");} } out.print("]"); out.flush(); out.close(); }
将数据库内信息拼接成完整字符串,效果如下:
这是不是就有点像腾讯请求的那个json文件呢?