Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ error...

Asked 1 years ago, Updated 1 years ago, 139 views

We are currently trying to communicate with Android Studio using retrofit2 library.

The server is using the restful API and responds with a json type.

Expected BEGIN_ARRAY but BEGIN_OBJECT at line 1 column 2 path $ There is an error like this, but the problem occurs only when I try to import more than two in the current array. (One is well received)

I don't think I'm getting the right data format.I don't know what to do. I can't understand even if I search it, so please help me.

Below is a single data type part.

@JsonIgnoreProperties(ignoreUnknown=true)
public class ResultsVersion {

    private String file_name;
    private String version;

    public String getFile_name() {
        return file_name;
    }

    public void setFile_name(String file_name) {
        this.file_name = file_name;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }
}

Below are two or more array data types.

public class ResultsVersionList {

    private ResultsVersion[] resultsVersions;

    public ResultsVersion[] getResultsVersions() {
        return resultsVersions;
    }

}

Below is the part that manages the restful API address.

@Headers("Content-Type: application/json")
    @GET(Constant.URL_CURRENT_FIRMWARE_VERSION)
    Call<ResultsVersionList> getCurrentFirmwareVersionList();

Below is the json data sent by the server.

[
    {
        "file_name": "app5910.apk",
        "version": "5.9.10"
    },
    {
        "file_name": "app533.apk",
        "version": "5.3.3"
    },
    {
        "file_name": "app532.apk",
        "version": "5.3.2"
    },
    {
        "file_name": "app5101.apk",
        "version": "5.10.1"
    }
]

android restful retrofit2

2022-09-21 23:16

1 Answers

Call<List<ResultsVersion>> getCurrentFirmwareVersionList();

Can't we get it this way?

Take it as an object and put it on the list.


2022-09-21 23:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.