1. 字符串形式:
[ { "userid": "admin", "name": "admin", "password": "MTIzNDU2", "flag": 1, "createtime": 1467277229000, "nickname": "", "thumbnail": null, "lastDate": null, "status": null, "region": "22222" }, { "userid": "administrator", "name": "administrator", "password": "MTIzNDU2", "flag": 0, "createtime": 1467252566000, "nickname": "超級管理員用戶", "thumbnail": null, "lastDate": null, "status": null, "region": "" } ]
2. javabean
import java.util.Date; public class User { private String userid; private String name; private String password; private Byte flag; private Date createtime; private String nickname; private String thumbnail; private Date lastDate; private Byte status; private String region; public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid == null ? null : userid.trim(); } public String getName() { return name; } public void setName(String name) { this.name = name == null ? null : name.trim(); } public String getPassword() { return password; } public void setPassword(String password) { this.password = password == null ? null : password.trim(); } public Byte getFlag() { return flag; } public void setFlag(Byte flag) { this.flag = flag; } public Date getCreatetime() { return createtime; } public void setCreatetime(Date createtime) { this.createtime = createtime; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname == null ? null : nickname.trim(); } public String getThumbnail() { return thumbnail; } public void setThumbnail(String thumbnail) { this.thumbnail = thumbnail == null ? null : thumbnail.trim(); } public Date getLastDate() { return lastDate; } public void setLastDate(Date lastDate) { this.lastDate = lastDate; } public Byte getStatus() { return status; } public void setStatus(Byte status) { this.status = status; } public String getRegion() { return region; } public void setRegion(String region) { this.region = region == null ? null : region.trim(); } }
3. 轉化
String listUsers = userClient.listUsers(); JSONArray jArray= JSONArray.fromObject(listUsers); Collection collection = JSONArray.toCollection(jArray, User.class); List<User> userList = new ArrayList<User>(); Iterator it = collection.iterator(); while (it.hasNext()) { User user = (User) it.next(); userList.add(user); }