Justin Thomas
Justin Thomas

Reputation: 5848

Kotlin Get Value from JSON

In the kotlin repl:

>>> import java.io.StringReader
>>> val json = p.parse(StringReader("""{"abc":"123"}""")) as JsonObject
>>> json.string("abc")
error: unresolved reference: string
json.string("abc")
     ^

>>> json
JsonObject(map={abc=123})

Get error unresolved reference. None of the examples here: https://github.com/cbeust/klaxon work

Upvotes: 2

Views: 2860

Answers (1)

hotkey
hotkey

Reputation: 148189

You need to import the string function as well, since it is an extension function, and it is not imported together with its receiver type Parser by default:

import com.beust.klaxon.string
json.string("abc")

Upvotes: 4

Related Questions