首页 > 代码库 > ObjectMapper 返回json 串

ObjectMapper 返回json 串

@RequestMapping(value="http://www.mamicode.com/getCountyBycityId")
public void getCountyBycityId(HttpServletRequest request,HttpServletResponse response) throws Exception{
Long cityId = Long.parseLong(request.getParameter("cityId"));
ObjectMapper mapper = new ObjectMapper();
List<CrmProvinceCity> list = creditContractService.getCountyBycityId(cityId);
String jsonString = mapper.writeValueAsString(list);
response.setContentType("text/json;charset=utf-8");
response.getWriter().print(jsonString);
}

ObjectMapper 返回json 串