-1

If I'm using javascript (or TypeScript), I can do following (just idea);

object = JSON.parse(jsonString)

And I can just use it like this,

alert(object.property);

Super Simple.

If I'm using Java, I need to create classes and parse it to use it. I understand.

How about Kotlin and Swift. They have optional types, so why single line, Javascript-like simple parsing doesn't exist for them, or does it? (Without even data class or going through JSON's properties)

Mohamed
  • 1,251
  • 3
  • 15
  • 36
  • 1
    [yes](https://developer.apple.com/documentation/foundation/jsonserialization) for swift but for Kotlin you'll need to use something like [Klaxon](https://stackoverflow.com/questions/41928803/how-to-parse-json-in-kotlin). If you are asking about native support without the use of a class, probably not. – aug Sep 05 '17 at 16:44
  • @aug: Your first link is only for Kotlin transpiled to Javascript. – SLaks Sep 05 '17 at 16:45
  • @SLaks my bad updated my comment – aug Sep 05 '17 at 16:48
  • 1
    Kotlin does not have optional types; Kotlin has type inference. You still need to declare all the classes that you use in Kotlin code. – yole Sep 06 '17 at 07:39
  • What is `Any` then? @yole – Mohamed Sep 06 '17 at 22:30
  • 1
    `Any` is Kotlin's equivalent to `java.lang.Object`: http://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html – yole Sep 07 '17 at 11:00

1 Answers1

1

If you look up what JSON stands for it's no wonder why JavaScript has "native support" for it: JavaScript Object Notation

In Kotlin you'll need to use libraries for parsing JSON, I'd recommend Jackson for that, a library widely used with Java already.

s1m0nw1
  • 76,759
  • 17
  • 167
  • 196