如何将JSON String解析为java对象

时间:2017-03-30 06:22:31

标签: java json

我有一个JSON字符串,我想从中提取值。

@RequestMapping(value = "/userrecords",method = RequestMethod.POST)
public @ResponseBody Response saveList(@RequestBody String str,Model model)
throws ParseException, SQLIntegrityConstraintViolationException {
System.out.println("--welcome--"+str.toString());//output:[{"name":"xxx","email":"xxx@gmail.com","message":"sdfasd"},{"name":"yyy","email":"yyy@gmail.com","message":"sdfasd"}]
//here i want all names,emails and messages
} 

我有一个带有setter和getter的pojo类User

1 个答案:

答案 0 :(得分:0)

您可以使用

Gson gson = new Gson(); 
User user = gson.fromJson(str.toString(), User.class);