2017-02-17 11 views
-1

retrofitを使用してapiから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; 
    } 

答えて

0

またそうであるように見えるがcom.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 2 column 1 path $ .Iはproblem.Hereが私のJSONデータでいただきました!知りません私はあなたのjsonデータを発行します。問題の原因となっているデータの間には、改行文字はほとんどありません。あなたの後ろに1つの新しい行の文字が"text":"Sandip Ghosh liked your photo."にあります。以下は有効なJSONです。あなたは、JSON here.

{ 
"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", 
    "username": "sandip", 
    "firstname": "Sandip", 
    "lastname": "Ghosh", 
    "imgname": "" 
}] 
} 
+0

それは同じで、それは私によって作成されます。私はあなたが存在するjsonデータが私が持っていることを意味します。 –

+0

実際にはデータによって同じですが、無効です。 jsonとhttp://jsonlint.com/またはhttp://www.jsoneditoronline.org/の両方を確認できます。あなたは何がエラーであるかを知るようになります。 – Sanjeet

+0

いいえ、同じプロジェクトで作業している他の人が同じjsonデータをフェッチするのは正しいです。 –

0

問題はAPIで、あなたの応答を微調整してみてくださいでの有効性を確認することができます。私はGsonや改造を使用してみましたし、私のために() レトロフィット=新しいretrofit.builder()それは見事に を失敗したか、あなたは

Okhttpクライアント=新しいokhttpを使用して試みることができます。 BaseUrl(あなたのURL) Setclient(クライアント).addconverterFactory(GsonConverterFactory.create(gson))。ビルド

+0

srryですが、構文が正しくないため、より明瞭に記述できます。 –

関連する問題