fastjson怎么將map轉(zhuǎn)成json對象?
寫入以下代碼即可實(shí)現(xiàn):
public static void main(String[] args) {
User_DAL userDal = new User_DAL();// 創(chuàng)建數(shù)據(jù)訪問對象
ResponseResult<User> ret = userDal.getUserList("id < 50", 2, 10);// 查詢ID小于50的用戶,保存到分頁類中
String JSON = JSON.toJSONString(ret, true); // 將對象轉(zhuǎn)換成json字符串,true為格式化輸出
System.out.println(json);
List<User> list = JSON.parseArray("{{name:123},{name:456}}", User.class);//將json字符串,轉(zhuǎn)換成Java對象數(shù)組
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName());
}
}