主要的json处理的包有 阿里开源的fastjson以及谷歌的gson,其它的有jackson等
其都支持 json对象与javaBean对象间的转换(javaBean对象通常指json的字符串)
fastjson中通过postman发送json数据,Controller层进行接收。Controller层的代码如下:
@RestController
@RequestMapping("user")
public class getJSONController {
@RequestMapping(value="/send", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public String getJSON(@RequestBody JSONObject jsonPram) {
JSONObject jsonObject = new JSONObject();
System.out.println(jsonPram.toString());
// 跳转到相应的jsp页面
return jsonPram.toJSONString();
}
}
json对象,json字符串,json的map间可以相互进行转换,其具体的转换代码如下: