Json格式的数据怎么转换成List
1个回答
展开全部
将Json数据转换成java中的List
[java] view plain copy
/**
* 将json格式封装的列表数据转换成java的List数据
* @return
*/
private static Object JSON2List() {
String jsonArray =
"[{\"age\":23,\"id\":123,\"name\":\"tt_2009_0\",\"province\":\"上海\",\"sex\":\"男\"}," +
"{\"age\":24,\"id\":123,\"name\":\"tt_2009_1\",\"province\":\"上海\",\"sex\":\"男\"}," +
"{\"age\":32,\"id\":123,\"name\":\"tt_2009_9\",\"province\":\"上海\",\"sex\":\"男\"}]";
return JSONArray.toList(JSONArray.fromObject(jsonArray), new SimpleUser(), new JsonConfig());
}
[java] view plain copy
/**
* 将json格式封装的列表数据转换成java的List数据
* @return
*/
private static Object JSON2List() {
String jsonArray =
"[{\"age\":23,\"id\":123,\"name\":\"tt_2009_0\",\"province\":\"上海\",\"sex\":\"男\"}," +
"{\"age\":24,\"id\":123,\"name\":\"tt_2009_1\",\"province\":\"上海\",\"sex\":\"男\"}," +
"{\"age\":32,\"id\":123,\"name\":\"tt_2009_9\",\"province\":\"上海\",\"sex\":\"男\"}]";
return JSONArray.toList(JSONArray.fromObject(jsonArray), new SimpleUser(), new JsonConfig());
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询