Je reçois à chaque fois cette erreur: attendue begin_array mais était begin_object Je ne sais pas si j'ai besoin d'ajouter un désérialiseur ou une classe warrper pour rénover mais je ne sais pas comment je peux le faire d'une manière facile à monter ma api réponse JSON pour tout mon projet, voici mon code retrofit essayer:Retrofit 2.0.0 beta2: attendu begin_array mais était begin_object
-
mon Json:
{
categoryDetails: [
{
id: "1",
categoryName: "Fashion"
},
{
id: "2",
categoryName: "Pets"
},
{
id: "3",
categoryName: "Sports"
},
{
id: "4",
categoryName: "Autre1"
},
{
id: "5",
categoryName: "Autre2"
}
]
}
Mon code source
import java.util.List;
import java.io.IOException;
import java.util.List;
import android.util.Log;
import retrofit.Call;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.http.GET;
import retrofit.http.Path;
public class GitHubClient {
public static final String API_URL = "http://192.168.1.22";
public static class Category {
public final String categoryName;
public final int id;
public Category(String categoryName, int id) {
this.categoryName = categoryName;
this.id = id;
}
}
/*-----------------------------------------------------------------------------------------------------------*/
public interface QampaAPI {
@GET("/api/category")
Call<List<Category>> categoryDetailss();
}
/*-----------------------------------------------------------------------------------------------------------*/
public static void main(String... args) throws IOException {
Log.w("retrofit","main()");
// Create a very simple REST adapter which points the GitHub API.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Create an instance of our GitHub API interface.
QampaAPI apiCall = retrofit.create(QampaAPI.class);
// Create a call instance for looking up Retrofit categoryDetailss.
Call<List<Category>> call = apiCall.categoryDetailss();
// Fetch and print a list of the categoryDetailss to the library.
List<Category> Categorys = call.execute().body();
for (Category Category : Categorys) {
Log.w("retrofit",Category.categoryName + " (" + Category.id + ")");
}
}
}
Toujours me donner la même erreur – Mourad
j'ai toujours la même erreur ici est mon code: collabedit.com/qbn3p – Mourad
il suffit d'utiliser la liste. Je pense que cela va résoudre votre problème –