1

JSON decoding was improved in Swift4

you simply just call JSONDecoder().decode and give it the json object and it will be converted into object

here is an example of that way

https://roadfiresoftware.com/2018/02/how-to-parse-json-with-swift-4/

my question that is there a way in Kotlin similar to the new way in Swift4 ?

Ali Al-Hudhud
  • 55
  • 2
  • 7

1 Answers1

1

Yes, Android has had that for quite a few years now.

It's a library from Google themselves, called GSON:
https://github.com/google/gson

Example:

Gson gson = new GsonBuilder().create();
gson.fromJson("MY JSON STRING", MyClass.class);

There are many overloads for the 'fromJson' function. There is also a 'toJson' function, to turn an object into a JSON string.

This is not just for Kotlin, it also works in Java.

Moonbloom
  • 7,738
  • 3
  • 26
  • 38