赞
踩
RootEntity
- `
- package com.ithelei;
- import java.util.List;
-
- public class RootEntity {
-
- private String errorCode;
- private String errorMsg;
- private List<UserEntity> data;
-
- public String getErrorCode() {
- return errorCode;
- }
-
- public void setErrorCode(String errorCode) {
- this.errorCode = errorCode;
- }
-
- public String getErrorMsg() {
- return errorMsg;
- }
-
- public void setErrorMsg(String errorMsg) {
- this.errorMsg = errorMsg;
- }
-
- public List<UserEntity> getData() {
- return data;
- }
-
- public void setData(List<UserEntity> data) {
- this.data = data;
- }
-
- @Override
- public String toString() {
- return "RootEntity [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", data=" + data + "]";
- }
-
- }
- `
UserEntity
- `package com.ithelei;
-
- public class UserEntity {
-
- private String position;
- private String userName;
- private String webAddres;
-
- public String getPosition() {
- return position;
- }
-
- public void setPosition(String position) {
- this.position = position;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getWebAddres() {
- return webAddres;
- }
-
- public void setWebAddres(String webAddres) {
- this.webAddres = webAddres;
- }
-
- @Override
- public String toString() {
- return "UserEntity [position=" + position + ", userName=" + userName + ", webAddres=" + webAddres + "]";
- }
-
- }
- `
JSONTest
- `public static void main(String[] args) {
- setBeanToJSON();
- }
- `
-
- `
- public static void setBeanToJSON() {
-
- RootEntity rootEntity = new RootEntity();
- rootEntity.setErrorCode("0");
- rootEntity.setErrorMsg("调用接口成功");
-
- List<UserEntity> data = new ArrayList<UserEntity>();
-
- UserEntity userEntity = new UserEntity();
- userEntity.setPosition("技术网站负责人");
- userEntity.setUserName("贺雷");
- userEntity.setWebAddres("www.ithelei.com");
- data.add(userEntity);//集合中装对象
-
- rootEntity.setData(data);
- System.out.println(new JSONObject().toJSONString(rootEntity));
- }`
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。