import net.sf.ezmorph.object.DateMorpher;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;
public static List jsonToObjectList(String jsonString, Class entityClass,String[] dataFormats) {
JSONArray jsonArray = JSONArray.fromObject(jsonString);
List objectList = new ArrayList();
for (Iterator iter = jsonArray.iterator(); iter.hasNext();) {
JSONObject jsonObject = (JSONObject) iter.next();
JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dataFormats));
objectList.add(JSONObject.toBean(jsonObject, entityClass));
}
return objectList;
}
例如:
List<UserDto> dtos = JsonUtil.jsonToObjectList(gridStr, UserDto.class,new String[]{"yyyy-MM-dd","yyyy-MM-ddTHH:mm:ss"});
将JSON数据转换成List对象,转换有日期格式的
最新推荐文章于 2024-01-30 11:11:20 发布