В настоящее время я изучаю Retrofit.Я пытаюсь проанализировать мой ответ JSON, который выглядит следующим образом:
{
"code": 0,
"message": "Success",
"billers": [
{
"billerCode": "001 ",
"billerName": "ABACUS BOOK CARD CORPORATION ",
"billerType": "C",
"label1": "Branch Code ",
"label2": "Origin of Deposit ",
"label3": "Collection Date ",
"label4": " ",
"label5": " "
},
{
"billerCode": "195 ",
"billerName": "ACCTN INC. ",
"billerType": "C",
"label1": "Account No. ",
"label2": "Subcriber's Name ",
"label3": null,
"label4": null,
"label5": null
},
И в настоящее время я использую его в качестве моего API в Retrofit:
public interface Api {
String BASE_URL = "my url"
@GET("get-billers")
Call<List<Hero>> getHeroes();
}
В настоящее время не знаю, как я могуполучить "Код", "сообщение" и массив "биллеры" и внутри биллеров массива.Я хочу получить "billercode".
Я использовал веб-страницу Пример модификации Android - выборка JSON с URL в качестве справочной информации при изучении Retrofit.
ОБНОВЛЕНИЕ:
Я применил ваш ответ, но потом все равно не могу разобрать содержимое JSON.Вот мой код:
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) // Here we are using the GsonConverterFactory to directly convert JSON data to object
.build();
Api api = retrofit.create(Api.class);
Call<List<Biller>> call = api.getBillers();
call.enqueue(new Callback<List<Biller>>() {
@Override
public void onResponse(Call<List<Biller>> call, Response<List<Biller>> response) {
String result = response.body().toString();
Gson gson = new Gson();
Type type = new TypeToken<List<Biller>>() {
}.getType();
heroList= gson.fromJson(result, type);
for (int i = 0; i < heroList.size(); i++) {
DebugUtils.log(""+heroList.get(i).getMessage());
DebugUtils.log(""+heroList.get(i).getCode());
}
}
@Override
public void onFailure(Call<List<Biller>> call, Throwable t) {
DebugUtils.log(""+ t.getMessage());
}
});