-
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) {
jsonToBean();
}
`
`public static void jsonToBean() {
String jsonStr = "{\"errorCode\": \"0\",\"errorMsg\": \"调用接口成功\",\"data\": [{\"userName\": \"贺雷\",\"position\": \"网站技术负责人\",\"webAddres\": \"www.ithelei.com\"}]}";
// 将json字符串转换成实体
RootEntity rootEntity = new JSONObject().parseObject(jsonStr, RootEntity.class);
System.out.println(rootEntity.toString());
}`
- 邮箱 :ithelei@sina.cn
- Good Luck!