1、JSON字符串转化成JSON对象
JSONObject jsonobject = JSON.parseObject(str);
或者 JSONObject jsonobject = JSONObject.parseObject(str);
2、
json="{\"userInfo\":{\"productId\":111,\"childId\":1,\"froms\":2}}";
UserFeedback user=JSON.parseObject(json).getObject("userInfo",UserFeedback .class);
3、String jsonString = "{name:'hqz',age:'18',sex:'male',haha:'sd'}";
/**
* JSON字符串转化成自己的实体类对象 test
*/
Test test = JSON.parseObject(jsonString, Test.class);
System.out.println(test.toString());
/**
* 对象转化成JSON 字符串
*/
String jsonStr = JSON.toJSONString(test);
System.out.println(jsonStr);
JSONObject strJson=JSONObject.parseObject(json);
Long productId = null;
if(strJson.containsKey("productId")){
String strProductId = strJson.getString("productId");
if(!StringUtil.isBlankStr(strProductId)){
productId = Long.parseLong(strProductId);
}else{
map.put("code","0");
map.put("msg","保存视频中途退出的反馈信息失败,productId为空");
}
}