标签:总结 html send ret 填充 pps appid turn 相同
String jsonStr = JSON.toJSONString(tableInfoVO.getFieldInfo());
https://www.cnblogs.com/dianzan/p/11332672.html
如下两个例子:
JSONObject jsonobject = JSON.parseObject(str);
或者:
JSONObject jsonobject = JSONObject.parseObject(str);
String s = httpRequest.sendGet("https://api.weixin.qq.com/sns/oauth2/access_token","appid=" + appId + "&secret=" + appSecret + "&code=" + code + "&grant_type=authorization_code"); UserAuthorizationReturn userAuthorizationReturn = JSON.parseObject(s, UserAuthorizationReturn.class);
具体例子:
public class Staff { private String name; private int age; private String sex; private Date birthday;
}
public static void main(String args[]) { //json字符串转化为对象 String jsonString = "{name:‘yxs‘,age:23,sex:‘man‘,telephone:‘12346‘}"; Staff staff = JSON.parseObject(jsonString, Staff.class); System.out.println(staff.toString()); //对象转化为json字符串 String string = JSON.toJSONString(staff); System.out.println(string); }
//输出结果
Staff{name=‘yxs‘, age=23, sex=‘man‘, birthday=null}
{"age":23,"name":"yxs","sex":"man"}
总结:在JSON。parseObject的时候,回去填充名字相同的属性,对于Json字符串中没有,而model类中有的属性,会为null,对于model类中没有,而json字符串中有的属性,不做任何处理
String jsonStr = JSON.toJSONString(tableInfoVO.getFieldInfo()); List<FiledInfoVO> filedInfoVOList = JSON.parseArray(jsonStr,FiledInfoVO.class);
标签:总结 html send ret 填充 pps appid turn 相同
原文地址:https://www.cnblogs.com/xuzhongyin/p/12971486.html