$("#div").html()如何显示一个集合?
$("#div").html()如何显示一个集合?
------解决方案--------------------
public static String encodeList(Object[] objs) {
return encodeList(Arrays.asList(objs));
}
@SuppressWarnings("unchecked")
public static String encodeList(Collection objs) {
JSONArray list = new JSONArray();
if (objs == null
------解决方案-------------------- objs.size() == 0)
return list.toString();
for (Object ae : objs) {
list.add(ae);
}
return list.toString();
}
@SuppressWarnings("unchecked")
public static String encodeObject(Object obj){
if(obj instanceof Collection)
return encodeList((Collection)obj);
JSONObject jo = JSONObject.fromObject(obj);
return jo.toString();
}
@SuppressWarnings("unchecked")
public static <T>List<T> decodeList(String str, Class<T> clazz) {
if (str == null
------解决方案-------------------- "".equals(str))
return null;
JSONArray obj = JSONArray.fromObject(str);
Object[] rts = obj.toArray();
List<T> result = new ArrayList<T>(rts.length);
for (int i = 0; i < rts.length; i++) {
Object jo = rts[i];
T ele = (T)JSONObject.toBean((JSONObject) jo, clazz);
result.add( ele );
}
return result;
}
@SuppressWarnings("unchecked")
public static <T>T decodeObject(String json,Class<T> clz){
JSONObject jsonObject = JSONObject.fromObject(json);
T bean = (T) JSONObject.toBean(jsonObject, clz);
return bean