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