Skip to content

Commit 2355f98

Browse files
committed
fix:添加数组的解析
1 parent 83d059a commit 2355f98

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

.idea/sonarlint/issuestore/5/9/59ca5d84a1197004f62a9cb9f53a7df61157ac7a

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FlowHttp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ afterEvaluate {
1919
// 这里头是artifacts的配置信息,不填会采用默认的
2020
groupId = 'com.github.buhuiming'
2121
artifactId = 'NetCore-Flow'
22-
version = '1.6.7'
22+
version = '1.6.8'
2323

2424
from components.release
2525
artifact androidSourcesJar //打包源码,去除这行打的包将看不到源码

FlowHttp/src/main/java/com/bhm/network/core/GsonResponseBodyConverter.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@ class GsonResponseBodyConverter<T> internal constructor(
3636
gson.fromJson(response, type)
3737
}
3838
} catch (e: Exception) {
39-
if (dataArr != null && "[]" == dataArr.toString()) {
40-
//这种情况是一个空数组,但是声明的却不是一个数组
41-
jsonObject.put(dataKey, null)
42-
gson.fromJson<T>(jsonObject.toString(), type)
43-
} else {
44-
throw ResultException(code, code, message, response)
39+
when {
40+
dataArr != null && "[]" == dataArr.toString() -> {
41+
//这种情况是一个空数组,但是声明的却不是一个数组
42+
jsonObject.put(dataKey, null)
43+
gson.fromJson(jsonObject.toString(), type)
44+
}
45+
dataArr != null && dataArr.length() > 0 -> {
46+
//这种情况是一个非空数组
47+
try {
48+
@Suppress("UNCHECKED_CAST")
49+
gson.fromJson<List<*>>(dataArr.toString(), type) as T
50+
} catch (e: Exception) {
51+
throw ResultException(code, code, message, response)
52+
}
53+
}
54+
else -> {
55+
throw ResultException(code, code, message, response)
56+
}
4557
}
4658
}
4759
}

0 commit comments

Comments
 (0)