If I send id, password to the server it has to give me a json
but It gives me an error.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path
This is Retrofit Code:
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();
}
});
}
This is the WebService Code:
public interface WebService {
@FormUrlEncoded
@POST("PastMain")
Call<PastMemo> getPastMain(
@FieldMap Map<String, String> user
);
}
This is PastMemo code
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: This the json which I have to get
[
{
"title": null,
"letter": null,
"date": null
},
{
"title": "a",
"letter": "b",
"date": "c"
}
]