build.gradle引入:
implementation 'com.google.code.gson:gson:2.8.6'
Gson gson = new Gson();
TestData myObject = gson.fromJson(你的服务器请求返回的Json字符串, new TypeToken<TestData>() {
}.getType());
列如:
{"time":1706083642359,"data":{"name":"你好","number":"18","type":"2024-01-24"},"resultCode":1}
public class TestData {
public int resultCode;
public String time;
public data data;
public class data{
public String name;
public String number;
public String type;
}
}
取值如 取type:
myObject.data.type;
网友评论