ITeye博客

phonegap-connection

fanfq · 2012-09-20 14:43 · html54mobile · 移动开发 · json · jQuery · HTML5 · PhoneGap · Markdown

在原有的demo基础上添加了jquery提交http请求以及返回数据的json解析。jquery不太熟好多年不用了,看样子要抓紧时间复习一下了。 index.html [code="java"] [/code] TestServlet.java 写了和servlet做测试用的,你可以用别的实现。 [code="java"] protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); //中文乱码问题 JSONObject jsonObj = new JSONObject(); JSONArray jsonArr = new JSONArray(); JSONObject jsonObjArr = new JSONObject(); JSONObject jsonObjArr1 = new JSONObject(); try { jsonObjArr.put("item1", "a"); jsonObjArr.put("item2", "b"); jsonArr.put(jsonObjArr); jsonObjArr1.put("item1", "c"); jsonObjArr1.put("item2", "d"); jsonArr.put(jsonObjArr1); jsonObj.put("rows", jsonArr); System.out.println(jsonObj.toString()); //{"rows":[{"item2":"b","item1":"a"},{"item2":"d","item1":"c"}]} out.print(jsonObj.toString()); out.close(); } catch (JSONException e) { e.printStackTrace(); } } [/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。