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包:
- commons-lang.jar
- commons-beanutils.jar
- commons-collections.jar
- commons-logging.jar
- ezmorph.jar
- json-lib-2.2.2-jdk15.jar
推荐看:
http://www.cnblogs.com/xwdreamer/archive/2011/12/16/2296904.html