-
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\": \"調(diào)用接口成功\",\"data\": [{\"userName\": \"賀雷\",\"position\": \"網(wǎng)站技術(shù)負(fù)責(zé)人\",\"webAddres\": \"www.ithelei.com\"}]}";
// 將json字符串轉(zhuǎn)換成實(shí)體
RootEntity rootEntity = new JSONObject().parseObject(jsonStr, RootEntity.class);
System.out.println(rootEntity.toString());
}`
- 郵箱 :ithelei@sina.cn
- Good Luck!