我使用retrofit从api中获取json数据。但是当我运行应用程序时显示错误com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 2 column 1 path $
。我不知道什么的problem.Here是我的JSON数据:
{"status":true,"message":"Notifications fetched.","data":
[{"id":"69","type":"liked","text":"Sandip Ghosh liked your photo.","for_userid":"56","from_userid":"55","for_image":"54","seen":"0",
"username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""},
{"id":"64","type":"liked","text":"Sandip Ghosh liked your
photo.","for_userid":"56","from_userid":"55","for_image":"54","seen":"0","userna
me":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""}]}
和我的接口类:
public static final String BASE_URL = "http://chikoop.com/api/index.php/";
private static Retrofit retrofit = null;
static Gson gson = new GsonBuilder()
.setLenient()
.create();
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
没有它的相同,它是由我创建的。我的意思是您提供的json数据与我拥有的相同。 –
的确如数据一样,但无效。您可以在http://jsonlint.com/或http://www.jsoneditoronline.org/查看这两个json。你会知道错误是什么。 – Sanjeet
不,这是正确的另一个谁在同一个项目上工作获取相同的JSON数据。 –