美文网首页
android gson解析

android gson解析

作者: 小黄牛 | 来源:发表于2024-01-23 16:13 被阅读0次

    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;

    相关文章

      网友评论

          本文标题:android gson解析

          本文链接:https://www.haomeiwen.com/subject/mxtpodtx.html