java - Android - 改造 : Error getting a response. Gson 错误

标签 java android gson retrofit okhttp

我已经设置了一个 API,可以通过 Retrofit 进行调用。 我是 Retrofit 的新手,但我相信我得到了响应,但是当它触发 onFailure() 时我得到了堆栈跟踪。

我正在 MainActivity.class 中使用 API。

这是什么意思,我该如何解决它。

堆栈跟踪: http://pastebin.com/ADXhxsFP

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

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/

相关文章:

java - 我如何知道Java中Word文档的确切扩展名

java - 无法将应用程序见解裸 API 添加到 Java Web 应用程序

android - 如何从 rtsp 流中截取 Android 的 VideoView 的屏幕截图?

java - 使用 Gson 解析复杂的嵌套 JSON 数据

android - Json 解析与 gson 不工作

java - 在 Spring MVC Hibernate 应用程序中,我应该在哪里保存用户图像?

java - Hibernate5 - 将所有 VARCHAR(255) 更改为 TEXT 而不逐个字段映射?

c# - 如何使 Xamarin 应用全屏(全屏)

android - 应用程序 apk 大小超过 100mb。如何上传到 PlayStore?

java - 如何将任意 JSON 转换为 Java 中可用的结构