Convert string in json format to list & lt; Bean & gt;, jsonbean

Source: Internet
Author: User

Convert string in json format to list <Bean> and jsonbean

1. string format:

[{"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 ": "Super administrator user", "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. Conversion

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.