Java使用org.json实现将json转换为bean
将jsonObject转换为目标bean,代码如下:
public static Object toBean(JSONObject jsonObject, Object object) throws IllegalAccessException {
for(Field field : object.getClass().getDeclaredFields()) {
field.setAccessible(true);
field.set(object, jsonObject.get(field.getName()));
}
return object;
}