Parsing Complex JSON in Flutter
Let’s talk about Parsing Complex JSON in Flutter. I know it becomes more complex when we get JSON which are nested like MAP->LIST->MAP->LIST.
Let’s start with a complex JSON example. (I suppose you have little bit knowledge of parsing simple JSON data)
Below is the Complex JSON:
If we study the above JSON we can see that “result” is a list which has “userInfo” and “bookData” as list too.
To parse this type of JSON we have to create PODO (Plain Old Dart Object)
STEP 1: Create a PODO
Here we have to create 4 PODO class which are Product, Result, UserInfo, and BookData.
As “result” is a list we have to create a List<Result> which can be passed in Products similarly for UserInfo and BookData we have to create List for both.
STEP 2: Fetching Data and Display
For fetching the data “dart:convert” and “http” package has been used.
To iterate throw the JSON for example to get all books name we can build a listview builder and then call “rest.result[index].bookDatas[0].bookName”.
If case you want full source code, I have linked my Github Repo
Thanks for reading this article ❤
And that’s it for this Fluttery article. This article may not be the best Complex JSON parsing article out there.
If I got something wrong? Let me know in the comments. I would love to improve.
Clap 👏 If this article helps you.