Gson下载地址:http://repo1.maven.org/maven2/com/google/code/gson/gson/

下载好后直接添加至lib即可

或者:

maven 

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.6</version>
</dependency>

Gradle

dependencies {
  implementation 'com.google.code.gson:gson:2.8.6'
}

2.使用

这里需要一个Bean类,只需要和你的json字段一一对应即可。

如:

public class CheckGoalBean {
    long goalID;
    String goalContent;
    int goalType;

    @Override
    public String toString() {
        return "CheckGoalBean{" +
                "goalID=" + goalID +
                ", goalContent='" + goalContent + '\'' +
                ", goalType=" + goalType +
                '}';
    }

    public long getGoalID() {
        return goalID;
    }

    public void setGoalID(long goalID) {
        this.goalID = goalID;
    }

    public String getGoalContent() {
        return goalContent;
    }

    public void setGoalContent(String goalContent) {
        this.goalContent = goalContent;
    }

    public int getGoalType() {
        return goalType;
    }

    public void setGoalType(int goalType) {
        this.goalType = goalType;
    }
}
CheckGoalBean.class

相关文章: