我已经设置了一个 API,可以通过 Retrofit 进行调用。 我是 Retrofit 的新手,但我相信我得到了响应,但是当它触发 onFailure() 时我得到了堆栈跟踪。
我正在 MainActivity.class 中使用 API。
这是什么意思,我该如何解决它。
堆栈跟踪: http://pastebin.com/ADXhxsFP
Gradle :
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'
最佳答案
您确实收到了来自服务器的响应。
尝试添加 LoggingInterceptor,以便增加响应的详细程度。 https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor
此外,我相信您正在尝试读取与 API 提供的格式不同的 JSON 格式。例如,当 GSON 转换器尝试解析以 {
开头的对象但得到 "
字符串(在 API 响应的第 14 列中搜索该 "
)时,就会发生 IllegalStateException。
看看您是否有正确的 POJO 来处理该请求,如果没有,您可以使用 http://www.jsonschema2pojo.org/ 创建新的 POJO
关于java - Android - 改造 : Error getting a response. Gson 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34959737/