Gson简单使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014688027/article/details/79963747
/**
 * Created by wangliang on 2018/4/16.
 * 说明:
 */

public class MeetNoticeEntity {
    /**
     * msgType : 1
     * meetingTheme : 2
     * meetingID : 1
     * meetingPWD : 1
     */

    private String msgType;
    private String meetingTheme;
    private String meetingID;
    private String meetingPWD;

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public String getMeetingTheme() {
        return meetingTheme;
    }

    public void setMeetingTheme(String meetingTheme) {
        this.meetingTheme = meetingTheme;
    }

    public String getMeetingID() {
        return meetingID;
    }

    public void setMeetingID(String meetingID) {
        this.meetingID = meetingID;
    }

    public String getMeetingPWD() {
        return meetingPWD;
    }

    public void setMeetingPWD(String meetingPWD) {
        this.meetingPWD = meetingPWD;
    }

    @Override
    public String toString() {
        return "MeetNoticeEntity{" +
                "msgType='" + msgType + '\'' +
                ", meetingTheme='" + meetingTheme + '\'' +
                ", meetingID='" + meetingID + '\'' +
                ", meetingPWD='" + meetingPWD + '\'' +
                '}';
    }

}

注:以上内容可使用快捷方式生成:首先新建类,在类中右键,选择generate ==> GsonFormat,将Json字符串粘贴进去,确定即可

 1.配置Gson

直接在build.gradle中引用

compile 'com.google.code.gson:gson:2.8.1'

2.调用Gson解析

String str={msgType='1', meetingTheme='1', meetingID='1', meetingPWD='1'}

Gson gson = new Gson();
MeetNoticeEntity meet = gson.fromJson(str, MeetNoticeEntity.class);
Log.i("====>",meet.toString());
Log.i("====>",meet.getMeetingID()+","+meet.getMeetingTheme()+","+meet.getMsgType()+","+meet.getMeetingPWD());

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页