From eee9097273270067a1025559cf4c06316ef28529 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Tue, 10 May 2022 15:52:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=B9=A6=E6=BA=90=E5=AF=BC=E5=85=A5):no=20?= =?UTF-8?q?path=20$.sourceUrls=20find?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit json.read找不到会抛出异常 --- .../app/ui/association/ImportBookSourceViewModel.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 93cc32bc0..248a78276 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -90,13 +90,14 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { val mText = text.trim() when { mText.isJsonObject() -> { - val json = JsonPath.parse(mText) - val urls = json.read>("$.sourceUrls") - if (!urls.isNullOrEmpty()) { - urls.forEach { + kotlin.runCatching { + val json = JsonPath.parse(mText) + json.read>("$.sourceUrls") + }.onSuccess { + it.forEach { importSourceUrl(it) } - } else { + }.onFailure { BookSource.fromJson(mText).getOrThrow().let { allSources.add(it) }