jsp传数据到后台处理多余的key value,即JSON类型的String转为JSON,处理好后再转为String

	import com.alibaba.fastjson.JSONArray;
	import com.alibaba.fastjson.JSONObject;
	import java.util.List;
	
	@RequestMapping(value = "/{contentId}/newContent", method = RequestMethod.POST)
	public String newContent(@RequestParam(required = true) String dataJson, HttpServletRequest request) throws Exception {
		JSONArray parse = JSONArray.parseArray(dataJson);
		JSONArray json = new JSONArray();
		String jsonStr = "";
		for (int i = 0; i < parse.size(); i++) {
			JSONObject jsonObject = parse.getJSONObject(i);
			jsonObject.remove("parentContentName");//去除多余的key value
			json.add(jsonObject);
			jsonStr = JSONObject.toJSONString(json);
		}
        List<Content> jsonContentList = new ObjectMapper().readValue(jsonStr, new TypeReference<List<Content>>() {//转换为实体类的list  (Content是实体类)
		});
		return "";
	}
上一篇:对象转化为字符串,字符串转化为对象


下一篇:RestAssured 接口自动化测试学习记录1