From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Parse JSON strings with Moshi

Parse JSON strings with Moshi

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Parse JSON strings with Moshi

After reading a file into memory, you can parse it using a variety of tools. In the past, many entry developers used Gson, a library from google. But recently the community has migrated to a newer JSON library called Moshi. I'll give you a quick demo of parsing data with Moshi and then I'll show you where the documentation is. First, I'll add a dependency for my build script for my app module. I'll add this down at the bottom of my existing dependencies, I'll start with implementation, and then in quotes the following string, com dot sqaureup dot moshi colon moshi dash kotlin colon one dot eight dot zero and that's the most recent as of the time of this recording. If there's a more recent version at the time you work through this course, use that. Now go back to my view model. I'll add a new function that I'll call parseText, and it will receive a text value typed as a string. I'll create a variable that I'll simply call Moshi and this represents an instance of the Moshi library. And…

Contents