я получаю сообщение об ошибке: ** Ожидается BEGIN_ARRAY, но BEGIN_OBJECT в строке 1 пути 24 столбца $ .result ** все еще пытается найти правильный путь, я попробовал другой способ, но все еще не могу приступить к работе.
это мой json пример:
{
"success": 1,
"result": [
{
"league_key": "1",
"league_name": "Superliga",
"country_key": "1",
"country_name": "Albania",
"league_logo": "https://allsportsapi.com/logo/logo_leagues/1_superliga.png",
"country_logo": "https://allsportsapi.com/logo/logo_country/1_albania.png"
}
]
}
здесь вы можете увидеть модель, которую я сделал, используя json2pojo
public class LeaguesResponse implements Parcelable {
@SerializedName("success")
@Expose
private Integer success;
@SerializedName("result")
@Expose
private List<Result> result = new ArrayList<>();
public final static Parcelable.Creator<LeaguesResponse> CREATOR = new Creator<LeaguesResponse>() {
@SuppressWarnings({
"unchecked"
})
public LeaguesResponse createFromParcel(Parcel in) {
return new LeaguesResponse(in);
}
public LeaguesResponse[] newArray(int size) {
return (new LeaguesResponse[size]);
}
};
protected LeaguesResponse(Parcel in) {
this.success = ((Integer) in.readValue((Integer.class.getClassLoader())));
in.readList(this.result, (com.pedrovs.leaguestandings.model.Result.class.getClassLoader()));
}
public LeaguesResponse() {
}
public Integer getSuccess() {
return success;
}
public void setSuccess(Integer success) {
this.success = success;
}
public List<Result> getResult() {
return result;
}
public void setResult(List<Result> result) {
this.result = result;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(success);
dest.writeList(result);
}
public int describeContents() {
return 0;
}
Результат класса
public class Result implements Parcelable
{
@SerializedName("league_key")
@Expose
private String leagueKey;
@SerializedName("league_name")
@Expose
private String leagueName;
@SerializedName("country_key")
@Expose
private String countryKey;
@SerializedName("country_name")
@Expose
private String countryName;
@SerializedName("league_logo")
@Expose
private String leagueLogo;
@SerializedName("country_logo")
@Expose
private Object countryLogo;
public final static Parcelable.Creator<Result> CREATOR = new Creator<Result>() {
@SuppressWarnings({
"unchecked"
})
public Result createFromParcel(Parcel in) {
return new Result(in);
}
public Result[] newArray(int size) {
return (new Result[size]);
}
}
;
protected Result(Parcel in) {
this.leagueKey = ((String) in.readValue((String.class.getClassLoader())));
this.leagueName = ((String) in.readValue((String.class.getClassLoader())));
this.countryKey = ((String) in.readValue((String.class.getClassLoader())));
this.countryName = ((String) in.readValue((String.class.getClassLoader())));
this.leagueLogo = ((String) in.readValue((String.class.getClassLoader())));
this.countryLogo = ((Object) in.readValue((Object.class.getClassLoader())));
}
public Result() {
}
public String getLeagueKey() {
return leagueKey;
}
public void setLeagueKey(String leagueKey) {
this.leagueKey = leagueKey;
}
public String getLeagueName() {
return leagueName;
}
public void setLeagueName(String leagueName) {
this.leagueName = leagueName;
}
public String getCountryKey() {
return countryKey;
}
public void setCountryKey(String countryKey) {
this.countryKey = countryKey;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String getLeagueLogo() {
return leagueLogo;
}
public void setLeagueLogo(String leagueLogo) {
this.leagueLogo = leagueLogo;
}
public Object getCountryLogo() {
return countryLogo;
}
public void setCountryLogo(Object countryLogo) {
this.countryLogo = countryLogo;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(leagueKey);
dest.writeValue(leagueName);
dest.writeValue(countryKey);
dest.writeValue(countryName);
dest.writeValue(leagueLogo);
dest.writeValue(countryLogo);
}
public int describeContents() {
return 0;
}
DataService:
public interface LeagueDataService {
@GET("api/football/?&met=Standings&leagueId=28&APIkey=78a1a6057999d384189812cf1f9e331e11cd1d0610eccb1b39e384efaf6056df")
Call<LeaguesResponse> getAllLeagues();
}
Метод в MainActivity
private void getAllLeagues() {
LeagueDataService leagueDataService = RetrofitInstance.getService();
Call<LeaguesResponse> call = leagueDataService.getAllLeagues();
call.enqueue(new Callback<LeaguesResponse>() {
@Override
public void onResponse(Call<LeaguesResponse> call, Response<LeaguesResponse> response) {
LeaguesResponse leaguesResponse = response.body();
if (leaguesResponse!=null && response.body()!=null){
leagueList = leaguesResponse.getResult();
showRecyclerView();
}
}
@Override
public void onFailure(Call<LeaguesResponse> call, Throwable t) {
Log.i("MyTest" , t.getMessage());
}
});
}
Я уже пытался передать результат Result в Call to List, любая помощь хороша, спасибо!