Ola, estou recebendo a String JSON abaixo, mas não consigo colocar os valores na Classe que eu criei, todos o valores ficam nulos.
Alguma dica?
JSON
{"USDT":{"code":"USD",
"codein":"BRLT",
"name":"Dólar Turismo",
"high":"4.09",
"low":"3.9",
"varBid":"0.13",
"pctChange":"3.103",
"bid":"4.08",
"ask":"4.32",
"timestamp":"1558121820000",
"create_date":"2019-05-17 16:39:00"
}
}
Fazendo a desserialização:
// Deserialization
//Gson gson = new Gson();
Moedas moedaDia = new Gson().fromJson(response.json, Moedas.class);
String line = "";
result.setResult(moedaDia);
Classe Moedas
public class Moedas {
public List<MoedaDia> USD;
public Moedas( List<MoedaDia> USD) {
this.USD = USD;
}
public List<MoedaDia> getValue() {
return USD;
}
public void setValue(List<MoedaDia> value) {
this.USD = value;
}
}
Classe MoedaDia:
public class MoedaDia {
public String code; //": "BRL",
public String codein; //": "BRL",
public String name; //": "Dólar Comercial",
public float high; //": "3,9766",
public float low; //": "3,9748",
public float varBid; //": "0,0021",
public float pctChange; //: "0,05",
public float bid; //": "3,9765",
public float ask; //": "3,9767",
public String timestamp; //": "1557873008",
public String create_date; //": "2019-05-14 21:00:05"
public MoedaDia(String code, String codein, String name, float high, float low, float varBid, float pctChange, float bid, float ask, String timestamp, String create_date) {
this.code = code;
this.codein = codein;
this.name = name;
this.high = high;
this.low = low;
this.varBid = varBid;
this.pctChange = pctChange;
this.bid = bid;
this.ask = ask;
this.timestamp = timestamp;
this.create_date = create_date;
}
}