Lorsque je tente d'envoyer un ArrayList <> en utilisant @POST sur Retrofit 2 à mon serveur web, le ArrayList <> est enregistré sur la base de données, mais le journal Android Je reçois l'erreur suivante:Erreur d'envoi ArrayList via POST sur Retrofit BEGIN_ARRAY prévu, mais a été STRING à la ligne 1 colonne 1
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
Je l'ai vu quelques questions ici, mais je ne pouvais pas le faire fonctionner, mais je suis un débutant et un peu perdu.
C'est le ArrayList:
ArrayList<ModelContact> listContact = new ArrayList<>();
ModelContact c = new ModelContact("5", "OFF", "Test", "12134567", "14646", "[email protected]", "Adress");
listContact.add(c);
c = new ModelContact("6", "ON", "Test2", "12123456", "14646", "[email protected]", "Adress");
listContact.add(c);
Ceci est mon Retrofit appel
Call<List<ModelContact>> callM = contactInterface.createRContact(listContact);
callM.enqueue(new Callback<List<ModelContact>>() {
@Override
public void onResponse(Response<List<ModelContact>> response, Retrofit retrofit) {
Log.i("TAG", "Success");
}
@Override
public void onFailure(Throwable t) {
Log.i("TAG", "Error: " + t.getMessage());
}
});
Et ceci est mon interface:
public interface ContactInterface {
@GET("recieve")
Call<List<ModelContact>> getRContact();
@POST("send")
Call<List<ModelContact>> createRContact(@Body ArrayList<ModelContact> modelContact);
}
réponse du serveur quand je fais une demande:
[{"id":"13","status":"ON","name":"Test","phone":"123","phone2":"1237855","email":"[email protected]","address":"adsfasd"},{"id":"14","status":"OFF","name":"Test","phone":"123","phone2":"125453","email":"[email protected]","address":"adsfasd"}]
classe ModelContatc:
public class ModelContact {
String id;
String status;
String name;
String phone;
String phone2;
String email;
String address;
public ModelContact(String id, String status, String name, String phone, String phone2, String email, String address) {
this.id = id;
this.status = status;
this.name = name;
this.phone = phone;
this.phone2 = phone2;
this.email = email;
this.address = address;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String nome) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String phone2() {
return phone2;
}
public void setPhone2(String phone2) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
le point de terminaison ne renvoie pas un json – Blackbelt
s'il vous plaît envoyer une chaîne json 'response' du serveur. il semble que votre serveur envoie une mauvaise réponse. Je ne vois aucune erreur dans la demande au serveur. – Tauqir
Posté la chaîne de réponse sur la question. – Rafael