如何通过GSON/Retrofit获得价值? [英] How to get the value with GSON / Retrofit?

查看:71
本文介绍了如何通过GSON/Retrofit获得价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用GSON/Retrofit提取文本"的值?

How to extract the value of "text" by using GSON/Retrofit?

    {
       code: 200,
       lang: "en-ms",
       text: [
           "Burung"
       ]
    }

推荐答案

1创建模型类

public class ResponseItem {

/**
 * code : 200
 * lang : en-ms
 * text : ["Burung"]
 */

private int code;
private String lang;
private List<String> text;

public int getCode() {
    return code;
}

public void setCode(int code) {
    this.code = code;
}

public String getLang() {
    return lang;
}

public void setLang(String lang) {
    this.lang = lang;
}

public List<String> getText() {
    return text;
}

public void setText(List<String> text) {
    this.text = text;
}

}

2在改造方法响应中:

 if (response.isSuccessful()) {
  ResponseItem responseItem;
  responseItem = response.body(); }

您可以通过说出responseitem.Get(您想从模型类中得到什么")来调用文本

and you can call text by saying responseitem.Get("whatever u want from the model class")

这篇关于如何通过GSON/Retrofit获得价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆