有关restful 怎么把json对象直接映射成java对象

2025-04-18 19:22:43
推荐回答(2个)
回答1:

用jackson吧,资料很多,给个demo吧

public static Object jsonToBean(String json, Class cls) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Object vo = mapper.readValue(json, cls);
return vo;
}
也可以看看这个博客 http://blog.csdn.net/songyongfeng/article/details/6932655

回答2:

可以用jackson或者JSON-lib这两个工具包