Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将JSON字符串解析为java对象_Java_Json - Fatal编程技术网

如何将JSON字符串解析为java对象

如何将JSON字符串解析为java对象,java,json,Java,Json,我有一个JSON字符串,我想从中提取值 @RequestMapping(value = "/userrecords",method = RequestMethod.POST) public @ResponseBody Response saveList(@RequestBody String str,Model model) throws ParseException, SQLIntegrityConstraintViolationException { System.out.println("

我有一个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

您可以使用

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

给那个画一个复制品。那个是给Java ME的,不是普通的Java。@Japu\u-D\u-Cret:对不起,我这里有多个JSON。@Japu\u-D\u-Cret:这不是重复的。请看我的输出。在你确定它是否重复后。很抱歉,它是重复的。将JSON转换为POJO后,通过调用getter“提取”值。这与解析无关,而且。。。坦白地说琐碎的。输出值的“问题”也是如此。如果不是的话,你在表达你在这里实际要求的东西方面做得很差。@Stephen:我找到了解决办法。通过使用JSONArray(字符串)