当我使用 volley 和 gson 时出现 MalformedJsonException
MalformedJsonException when I use volley and gson
我正在尝试使用 volley 和 gson 做一个小例子。我在 gradle 文件中有以下发布的依赖项。但是当我进行构建项目时,我收到了
发布错误。
你能告诉我如何解决吗
错误:
Error:com.google.common.util.concurrent.UncheckedExecutionException: java.lang.RuntimeException: com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.RuntimeException: com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1
gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'dev.dworks.libs:volleyplus:0.1.4'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.android.support:support-v4:25.0.+'
}
某些情况下可能会出现此错误。
从服务器发送 application/json 作为内容类型。
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
implementation 'com.google.code.gson:gson:2.6.1'
我正在尝试使用 volley 和 gson 做一个小例子。我在 gradle 文件中有以下发布的依赖项。但是当我进行构建项目时,我收到了 发布错误。
你能告诉我如何解决吗
错误:
Error:com.google.common.util.concurrent.UncheckedExecutionException: java.lang.RuntimeException: com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.RuntimeException: com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1
gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'dev.dworks.libs:volleyplus:0.1.4'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.android.support:support-v4:25.0.+'
}
某些情况下可能会出现此错误。
从服务器发送 application/json 作为内容类型。
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
implementation 'com.google.code.gson:gson:2.6.1'