2016-01-23 66 views
1

我已經建立了一個API,我通過Retrofit進行調用。 我是新的改造,但我相信我得到了一個響應,但是當它觸發onFailure()時我得到一個堆棧跟蹤。Android - Retrofit:獲取響應時出錯。 Gson錯誤

我正在使用MainActivity.class中的API。

這是什麼意思,我該如何解決。

堆棧跟蹤: http://pastebin.com/ADXhxsFP

源代碼: https://github.com/Axiom1999/Iron-Banner-Companion/tree/master/app/src/main/java/me/axiom/aapp/ironbannercompanion

搖籃:

compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' 
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' 
compile 'com.squareup.okhttp3:okhttp:3.0.1' 
compile 'com.google.code.gson:gson:2.5' 
+0

你的JSON創造新的有錯誤的語法,這是問題。你可以發佈你從服務器獲得的JSON響應嗎? –

+0

{「Response」:「4611686018439042298」,「ErrorCode」:1,「ThrottleSeconds」:0,「ErrorStatus」:「Success」,「Message」:「Ok」,「MessageData」:{}} – Axiom

+0

JSON是有效,所以我猜你是錯誤的POJO類轉換JSON。 –

回答

0

你確實是從服務器獲取的響應。

嘗試添加LoggingInterceptor,以便增加響應的詳細程度。 https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor

而且,我相信,你正在試圖讀取比API是給你一個不同的JSON格式。例如,當GSON轉換器試圖解析一個以{開頭的對象,但得到了"字符串(在您的API響應的第14列中搜索該")時,您的IllegalStateException發生。

看看你是否有合適的POJO來處理該請求,如果沒有可以用http://www.jsonschema2pojo.org/

+1

謝謝@Evin1_回覆。以下是我通過Google Chrome從服務器獲得的回覆。 {「Response」:「4611686018439042298」,「ErrorCode」:1,「ThrottleSeconds」:0,「ErrorStatus」:「Success」,「Message」:「Ok」,「MessageData」:{}} – Axiom