如果我發送身份證,密碼到服務器,它必須給我一個json
但它給我一個錯誤。翻新gson異常
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:預期BEGIN_OBJECT但BEGIN_ARRAY位於第1行第2列路徑
這是改造代碼:
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();
}
});
}
這是WebService代碼:
public interface WebService {
@FormUrlEncoded
@POST("PastMain")
Call<PastMemo> getPastMain(
@FieldMap Map<String, String> user
);
}
這是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;
}
}
編輯: 這裏面我有JSON獲得
[
{
"title": null,
"letter": null,
"date": null
},
{
"title": "a",
"letter": "b",
"date": "c"
}
]
請將該行發出相同的異常 – Mandy8055
我調試了所有行以檢查錯誤行,但不顯示。它只會去onFailure()方法。 – dogyhbin2