1
我希望你能給我一個我無法解決的Gson問題的手。自從我在這個主題上找到很多主題後,這顯然很平靜,但沒有設法使用答案。
我有這樣的錯誤:
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:預期BEGIN_OBjECT但STRING在第1分1條路徑$
這裏是我的JSON:
{"valeurs":[{"Ident":"1","Lien":"r8WzdMerigo","Categorie":"1"},{"Ident":"2","Lien":"neqgJGz08Fw","Categorie":"2"}],"success":1}
然後我POJO:
public class gitmodel {
@SerializedName("Ident")
@Expose
private int Ident;
@SerializedName("Lien")
@Expose
private String Lien;
@SerializedName("Categorie")
@Expose
private int Categorie;
public int getIdent() {return Ident;}
public String getLien() {
return Lien;
}
public int getCategorie() {
return Categorie;
}
}
終於在主要活動:
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(API)
.build();
gitapi git = restAdapter.create(gitapi.class);
git.getFeed("affichage_bd.php", new Callback<gitmodel>() {
@Override
public void success(gitmodel gitmodel, Response response) {
tv.setText("Numero categorie :" + gitmodel.getCategorie() + "\nLien :" + gitmodel.getLien() + "\nIdentification :" + gitmodel.getIdent());
}
@Override
public void failure(RetrofitError error) {
tv.setText(error.getMessage());
}
});
}
});
你能告訴我這是怎麼回事?
嗨Kushtrim和泰克的幫助! 但是,我不知道該怎麼辦? 我的回調是在界面中設置: 公共接口gitapi { @GET( 「/用戶/ {用戶}」) 公共無效getFeed(@Path( 「用戶」)的字符串的用戶,回撥響應); } 那我必須把MyModel實例放到哪裏?進入主要活動?我有點失望抱歉.... –
GrayFox
@GrayFox檢查編輯答案。 –
好的非常感謝你的編輯:)! 但是,似乎仍然發生錯誤。我發現我的數據錯誤與我的JSON。我測試了http://jsonlint.com/和相同的錯誤:預期的BEGIN_OBJECT,但是在第1行第1列的路徑$ 我不明白,我有一個括號在打開和關閉...... ??? ! – GrayFox