spring中处理json

1.使用fastJson

2.controller层

@PostMapping("")
@ResponseBody
public BaseResponse jsonFunction(@RequestBody String jsonData){
    BaseResponse baseResponse = new BaseResponse();

    JSONObject data = JSONObject.parseObject(jsonData);
    //处理基本类型
    Integer articleId = data.getInteger("articleId");
    String title = data.getString("title");
    //处理List
    List<ArticleVO> list = JSONArray.parseArray (jsonData, ArticleVO.class);
  
    return baseResponse;
}
posted @ 2023-02-21 00:12  lwx_R  阅读(16)  评论(0编辑  收藏  举报