Json中对象嵌套对象
Result result=new Result();Customer cu=new Customer();cu.setEmail("wangpeng@huapay.com");cu.setNick_name("王鹏");result.setCustomer(cu);net.sf.json.JSONObject fromObject = net.sf.json.JSONObject.fromObject(result); //json-lib 将对象转为jsonSystem.out.println(fromObject);String str = JSON.toJSONString(result);//fastjson 将对象转为json字符串 {"customer":{"email":"wangpeng@huapay.com","nick_name":"王鹏"}} {对象里面套对象}System.out.println(str);
打印结果为:
{"customer":{"nick_name":"王鹏","email":"wangpeng@huapay.com"}}
{"customer":{"email":"wangpeng@huapay.com","nick_name":"王鹏"}}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
