JSONObject与JSONArray的使用

示例:(部分忽略)

JSONArray jsons = new JSONArray();

ResultSet rs = DBProxy.executeQuery(sql);

while(rs.next()){

    JSONObject json = new JSONObject();

    String zbmc = rs.getString(1);

    String pzsl = rs.geString(2);

    json.put("sl",pzsl == null ? "":pzsl);

    json.put("mc",zbmc);

    jsons.add(json);

}

 

PrintWrite writer = resp.getWrite();

writer.print(jsons);

writer.close();

 

JAR包说明:

要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包:

  1. commons-lang.jar
  2. commons-beanutils.jar
  3. commons-collections.jar
  4. commons-logging.jar 
  5. ezmorph.jar
  6. json-lib-2.2.2-jdk15.jar

 

推荐看:

http://www.cnblogs.com/xwdreamer/archive/2011/12/16/2296904.html

 

posted @ 2017-07-15 10:28  乐在克里特  阅读(102)  评论(0编辑  收藏  举报