V
V
vgavdeev2016-11-28 00:57:31
Android
vgavdeev, 2016-11-28 00:57:31

Kotlin how to access the properties of a json object through a dot?

Kotlin how to access the properties of a json object through a dot? The object is returned to me by node.js api. For http requests I use the Fuel library. I am writing an android client. Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asd111, 2016-11-28
@asd111

import com.fasterxml.jackson.module.kotlin.*

data class User(val id: Int, val name: String)

fun main(args: Array<String>) {
    val mapper = jacksonObjectMapper()
    val json = """{"id": 10, "name": "Kirill"}"""
    val user = mapper.readValue<User>(json)
    println(user.name)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question