java怎么把字符串转成json字符串

如题所述

@RequestMapping(value = "updateInvestorApplyAccountNo", method = RequestMethod.POST)
@ResponseBody
public void updateInvestorApplyAccountNo(HttpServletRequest request,
HttpServletResponse response,
@RequestBody String requestBody) {
int num = 0;
String result = "";

//下面是把拿到的json字符串转成 json对象
JSONObject jsStr = JSONObject.parseObject(requestBody); //将字符串{“id”:1}
//int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值

/**
* json对象转换成java对象
*/
InvestorApplyModel stud = (InvestorApplyModel) JSONObject.toJavaObject(jsStr,InvestorApplyModel.class);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-02-13
有几种方式 第一 把字符串存到一个javabean 在 Controller通过@ResponseBody 转换成 JSON
或者 拼接字符串的形式 拼接成 json格式