当前位置: 首页 > 知识库问答 >
问题:

应为BEGIN_OBJECT,但为BEGIN_ARRAY改版[重复]

戴建义
2023-03-14

我正在尝试解析JSON代码,如下所示:

[
{
    "id": 1,
    "name": "Кафе 1",
    "tracks": [
           I think problem is here 
        {
            "id": 10,
            "name": "track 2.mp3",
            "url": "track 2.mp3",
       ...

这是我的apiinterface.java

@GET(".../playlists")
Call<FDYPlaylists> getPlaylists(@HeaderMap Map<String, String> headers);
public static final String BASE_URL = "url";

public static APIService getAPIService() {

    return RetrofitClient.getClient(BASE_URL).create(APIService.class);
}
 private static Retrofit retrofit = null;

public static Retrofit getClient(String baseUrl) {
    if (retrofit == null) {
        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}
 Map<String, String> map = new HashMap<>();
    map.put("Content-Type", "application/json");
    map.put("Authorization", "Bearer " + token);

    mAPIService.getPlaylists(map).enqueue(new Callback<FDYPlaylists>() {
       .....

这是我得到的错误:

应为BEGIN_OBJECT,但在第1行第2列处为BEGIN_ARRAY

共有1个答案

谷梁迪
2023-03-14

方括号反映有对象数组,所以请使用下面的代码

@GET(".../playlists")
Call<ArrayList<FDYPlaylists>> getPlaylists(@HeaderMap Map<String, String> headers);
 类似资料: