Here is my JSON look like
When I tried to access the son using list. I check that response.isSuccessful()
I am getting true in response but can not see data in model classes.
Here is my MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ApiInterface apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<List<Example>> call = apiInterface.getAdditionalProperties(APIClient.TOKEN,APIClient.SECRET,"1s","now");
call.enqueue(new Callback<List<Example>>() {
@Override
public void onResponse(Call<List<Example>> call, Response<List<Example>> response) {
if (response.isSuccessful())
Toast.makeText(MainActivity.this, String.valueOf(response.body().toString()), Toast.LENGTH_SHORT).show();
List<Example> exampleList = response.body();
for (int i = 0; i < exampleList.size(); i++) {
System.out.println(exampleList.get(i).getAccount());
}
}
@Override
public void onFailure(Call<List<Example>> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
APIClient.java
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
Here is my interface
public interface ApiInterface {
@GET("data?")
Call<List<Example>> getAdditionalProperties(@Query("mc_token") String token, @Query("mc_secret") String secret, @Query("utc_start") String startTime, @Query("utc_end") String endTime);
}
You can see my models look like this
Example
public class Example {
private String account;
private String type;
private String topic;
private String platform;
private double utcTimeApiReceived;
private String key;
private String device;
private Data data;
private String id;
private double utcTime;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public double getUtcTimeApiReceived() {
return utcTimeApiReceived;
}
public void setUtcTimeApiReceived(double utcTimeApiReceived) {
this.utcTimeApiReceived = utcTimeApiReceived;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getDevice() {
return device;
}
public void setDevice(String device) {
this.device = device;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getUtcTime() {
return utcTime;
}
public void setUtcTime(double utcTime) {
this.utcTime = utcTime;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
I checked this link and try It but it didn't help
If you would like to see my model code feel free.
Thank You