Si j'envoie un identifiant, mot de passe au serveur, il doit me donner un json
mais cela me donne une erreur.Retrofit gson exception
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: BEGIN_OBJECT attendu, mais était BEGIN_ARRAY à la ligne 1 colonne 2 chemin
C'est code Retrofit:
public void postCheckUser(String id, String password) {
retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(url)
.build();
Map map = new HashMap();
map.put("id",id);
map.put("password", password);
webService = retrofit.create(WebService.class);
Call<PastMemo> call = webService.getPastMain(map);
call.enqueue(new Callback<PastMemo>() {
@Override
public void onResponse(Call<PastMemo> call, Response<PastMemo> response) {
if (response.code() == 200) {
title = response.body().getTitle();
letter= response.body().getLetter();
date = response.body().getDate();
Toast.makeText(getActivity(), "SignIn Success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "SignIn Failed", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<PastMemo> call, Throwable t) {
Toast.makeText(getActivity(), "SignIn Denied", Toast.LENGTH_SHORT).show();
}
});
}
Ceci est le Code de service Web:
public interface WebService {
@FormUrlEncoded
@POST("PastMain")
Call<PastMemo> getPastMain(
@FieldMap Map<String, String> user
);
}
Ce code est PastMemo
public class PastMemo {
@SerializedName("title")
@Expose
private String title;
@SerializedName("letter")
@Expose
private String letter;
@SerializedName("date")
@Expose
private String date;
public String getTitle() {
return title;
}
public String getLetter() {
return letter;
}
public String getDate() {
return date;
}
}
EDIT: Ce JSON que je dois obtenir
[
{
"title": null,
"letter": null,
"date": null
},
{
"title": "a",
"letter": "b",
"date": "c"
}
]
Veuillez signaler la ligne à laquelle elle lance la même exception – Mandy8055
J'ai débogué toutes les lignes pour vérifier la ligne d'erreur mais elle n'apparaît pas. Il va seulement à la méthode onFailure(). – dogyhbin2