Код: Выделить всё
private fun testRegex() {
lifecycleScope.launch(ioDispatcher) {
try {
val text =
"{\"message\":\"Bad Gateway\",\"code\":502,\"errors\":[{\"message\":\"Failed to get configuration of type: ae.network.transaction.domain.config.FeatureToggleResponse\",\"localizedMessage\":\"{error.processing.configFetchError}\",\"errorCode\":\"configFetchError\",\"domain\":\"processing\"}]}"
val regex = "\\{(?:[^{}]*|\\{[^{}]*\\})*\\}".toRegex()
val jsonMatches = regex.findAll(text)
Log.d("json_matches", "jsonMatches= ${jsonMatches.count()}")
} catch (e: Exception) {
Log.d("json_matches", "exception: Never comes here")
} finally {
Log.d("json_matches", "finally: Never comes here")
}
}
}
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/792 ... ssed-and-n
Мобильная версия