package j2ee.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class JsonConvert {
@SuppressWarnings("unchecked")
//list 专程 jsonobject
public static JSONObject generate(List list) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("totalCount", list.size());
map.put("root", list);
return JSONObject.fromObject(map);
}
@SuppressWarnings("unchecked")
public static JSONArray generate1(List list) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("totalCount", list.size());
map.put("root", list);
return JSONArray.fromObject(map);
}
public static JSONObject javabean2json(Object object) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("success", true);
map.put("data", object);
return JSONObject.fromObject(map);
}
@SuppressWarnings("unchecked")
public static JSONObject objectcollect2json(List list, String total) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("totalProperty", total);
map.put("root", list);
return JSONObject.fromObject(map);
}
}