pull/1352/head
gedoor 3 years ago
parent 7f56b019e3
commit 460729f555
  1. 35
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt

@ -3,6 +3,7 @@ package io.legado.app.model.analyzeRule
import androidx.annotation.Keep import androidx.annotation.Keep
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.ReadContext import com.jayway.jsonpath.ReadContext
import io.legado.app.utils.printOnDebug
import java.util.* import java.util.*
@Suppress("RegExpRedundantEscape") @Suppress("RegExpRedundantEscape")
@ -40,11 +41,15 @@ class AnalyzeByJSonPath(json: Any) {
result = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...} result = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...}
if (result.isEmpty()) { //st为空,表明无成功替换的内嵌规则 if (result.isEmpty()) { //st为空,表明无成功替换的内嵌规则
val ob = ctx.read<Any>(rule) try {
result = if (ob is List<*>) { val ob = ctx.read<Any>(rule)
ob.joinToString("\n") result = if (ob is List<*>) {
} else { ob.joinToString("\n")
ob.toString() } else {
ob.toString()
}
} catch (e: Exception) {
e.printOnDebug()
} }
} }
return result return result
@ -73,11 +78,15 @@ class AnalyzeByJSonPath(json: Any) {
ruleAnalyzes.reSetPos() //将pos重置为0,复用解析器 ruleAnalyzes.reSetPos() //将pos重置为0,复用解析器
val st = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...} val st = ruleAnalyzes.innerRule("{$.") { getString(it) } //替换所有{$.rule...}
if (st.isEmpty()) { //st为空,表明无成功替换的内嵌规则 if (st.isEmpty()) { //st为空,表明无成功替换的内嵌规则
val obj = ctx.read<Any>(rule) //kotlin的Any型返回值不包含null ,删除赘余 ?: return result try {
if (obj is List<*>) { val obj = ctx.read<Any>(rule)
for (o in obj) result.add(o.toString()) if (obj is List<*>) {
} else { for (o in obj) result.add(o.toString())
result.add(obj.toString()) } else {
result.add(obj.toString())
}
} catch (e: Exception) {
e.printOnDebug()
} }
} else { } else {
result.add(st) result.add(st)
@ -124,7 +133,11 @@ class AnalyzeByJSonPath(json: Any) {
val rules = ruleAnalyzes.splitRule("&&", "||", "%%") val rules = ruleAnalyzes.splitRule("&&", "||", "%%")
if (rules.size == 1) { if (rules.size == 1) {
ctx.let { ctx.let {
return it.read<ArrayList<Any>>(rules[0]) try {
return it.read<ArrayList<Any>>(rules[0])
} catch (e: Exception) {
e.printOnDebug()
}
} }
} else { } else {
val results = ArrayList<ArrayList<*>>() val results = ArrayList<ArrayList<*>>()

Loading…
Cancel
Save