我使用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數據。 –