程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> 數組json格式的字符串 轉 list<Bean>,jsonbean

數組json格式的字符串 轉 list<Bean>,jsonbean

編輯:JAVA綜合教程

數組json格式的字符串 轉 list<Bean>,jsonbean


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);
        }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved