package com.ehm.hes.common;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
@SuppressWarnings("unchecked")
public class JsonUtil {
public static T jsonToBean(String json,Class clazz)
{
JSONObject jsonObject = JSONObject.fromObject(json);
return (T)JSONObject.toBean(jsonObject,clazz);
}
@SuppressWarnings("deprecation")
public static
List
jsonToList(String json,Class clazz)
{
System.out.println("json:"+json);
JSONArray arry=JSONArray.fromObject(json);
return JSONArray.toList(arry,clazz);
}
public static
T[] jsonToArray(String json,Class clazz)
{
JSONArray arry=JSONArray.fromObject(json);
return (T [])JSONArray.toArray(arry,clazz);
}
public static String listToJson(List> list)
{
return JSONSerializer.toJSON(list).toString();
}
}
导入
json-lib-2.4-jdk15.jar
页面遍历