json-lib-2.3-jdk15.jar escapse 单引号 双引号
List<?> objects = this.getSession().createSQLQuery(sql).setResultTransformer(
CriteriaSpecification.ALIAS_TO_ENTITY_MAP).list();
//modify by lKF43181
//对该方法进行修改是为了满足字符串中包含单引号或双引号
//例如 {"key":"'迭代21','迭代25','迭代81','迭代82'"}
//JSONArray jsonArray = new JSONArray();
JSONStringer jsonStringer = new JSONStringer();
jsonStringer.object().key("totalProperty").value(objects.size());
jsonStringer.key("msg");
jsonStringer.array();
for (Object object : objects)
{
//JSONObject jsonItem = new JSONObject();
Map<?, ?> mapObj = (Map<?, ?>) object;
Iterator it = mapObj.keySet().iterator();
jsonStringer.object();
while (it.hasNext())
{
String key = (String) it.next();
Object value = mapObj.get(key);
if(null == value)
{
value = "";
}
else if(value instanceof Date) {
value = (Object)DateUtil.formatDateTime((Date)value);
}
//jsonItem.put(key, value);
String valueStr = value.toString();
jsonStringer.key(key).value(valueStr);
}
jsonStringer.endObject();
}
jsonStringer.endArray();
jsonStringer.endObject();
/*JSONObject json = new JSONObject();
json.put("totalProperty", objects.size());
json.accumulate("msg", jsonArray.toString());*/
return jsonStringer.toString();