Search code examples
androidjsonkotlinretrofit2

Hello, I am receiving a json string, I need to separate data by class properties


I am receiving a json string, I need to separate data by class properties. The problem is that I can only know part of the key. For example, the key is 12345@666.777, I only know @666.777. Is it possible to somehow use regular expressions or look for values by part of the key?


Solution

  • I would iterate over all the keys in the JSON object as shown here: https://discuss.kotlinlang.org/t/iterating-over-json-properties/1940/2

    and check for every key if it contains the partial key I have as a substring using this standard Kotlin method: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/contains.html

    You also need to treat cases where the same substring is present in 2 different keys (if you think that is possible).