Я использую дооснащение2. Я делаю HTTP-вызовы и получаю данные JSON в качестве ответа:
[
{
"ActualTotalLoadByMonthValue": "4264156.37",
"AreaName": "Hungary",
"AreaTypeCode": "CTY",
"Dataset": "ActualTotalLoad",
"MapCode": "HU",
"Month": "1",
"ResolutionCode": "PT15M",
"Source": "entso-e",
"Year": "2018"
}
]
Я хочу взять контекст этого JSON и представить его в массиве, но для начала я не знаю, как получить контекст моего ответа. Я попытался с response.body (), но это не похоже на работу. Вот мой код:
val call = RequestManager.service.getactualtotalload(areaName,resolution, datetype ,"2018")
call.enqueue(object : Callback<List<Response1>> {
override fun onResponse(call: Call<List<Response1>>, response: Response<List<Response1>>)
{
loaderout.visibility = View.GONE
if (response.isSuccessful) {
Log.d("deee","Json " + response.body().toString())
openTableActivity()
} else {
}
}
override fun onFailure(call: Call<List<Response1>>, t: Throwable) {
loaderout.visibility = View.GONE
}
})
, в то время как Response1 выглядит так:
public class Response1 {
@SerializedName("ActualTotalLoadByMonthValue")
@Expose
private String actualTotalLoadByMonthValue;
@SerializedName("AreaName")
@Expose
private String areaName;
@SerializedName("AreaTypeCode")
@Expose
private String areaTypeCode;
@SerializedName("Dataset")
@Expose
private String dataset;
@SerializedName("MapCode")
@Expose
private String mapCode;
@SerializedName("Month")
@Expose
private String month;
@SerializedName("ResolutionCode")
@Expose
private String resolutionCode;
@SerializedName("Source")
@Expose
private String source;
@SerializedName("Year")
@Expose
private String year;
public String getActualTotalLoadByMonthValue() {
return actualTotalLoadByMonthValue;
}
public void setActualTotalLoadByMonthValue(String actualTotalLoadByMonthValue) {
this.actualTotalLoadByMonthValue = actualTotalLoadByMonthValue;
}
public String getAreaName() {
return areaName;
}
public void setAreaName(String areaName) {
this.areaName = areaName;
}
public String getAreaTypeCode() {
return areaTypeCode;
}
public void setAreaTypeCode(String areaTypeCode) {
this.areaTypeCode = areaTypeCode;
}
public String getDataset() {
return dataset;
}
public void setDataset(String dataset) {
this.dataset = dataset;
}
public String getMapCode() {
return mapCode;
}
public void setMapCode(String mapCode) {
this.mapCode = mapCode;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getResolutionCode() {
return resolutionCode;
}
public void setResolutionCode(String resolutionCode) {
this.resolutionCode = resolutionCode;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
Также мой RequestManager:
object RequestManager {
val interceptor = HttpLoggingInterceptor()
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
init {
//TODO must be None at live
interceptor.level = HttpLoggingInterceptor.Level.BODY
}
val retrofit = Retrofit.Builder()
.baseUrl("http://c6913be7.ngrok.io/energy/api/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
val service = retrofit.create(Api::class.java)
}
Любые советы о том, как получить доступ к данным а затем, как передать их в макет массива таблицы?