0
votes

I have two types of Json for my project ,i want to parse this json from from URL & I have one TextField in my App if i enter Register number in Textfield i want to get back the Halllocation or name.

{
   "Sheet1":[
      {
         "RegisterNumber":1718301002,
         "HallLocation":"224-MBA Block"
      },
      {
         "RegisterNumber":1718301005,
         "HallLocation":"224-MBA Block"
      }
   ]
}

and

{
   "Sheet1":[
      {
         "":"",
         "id":1517102001,
         "name":"103 - AI Building"
      }
   ]
}
1
Use app.quicktype.io for writing json parsing classes. Your 2nd json structure is wrong as it contains a key which is empty which results in generation of wrong data classes.shubhgkr

1 Answers

0
votes

After fetching that list of data you can use where to filter out the object which has the inserted Register Number in TextField,

Here is the example:

http.Response responseData = await http.get(url);
dynamic apiData = jsonDecode(responseData.body).where((item) =>
 item["RegisterNumber" ].toLowerCase() == insertedRegisterNumber.toLowerCase()
);

Now use that returned apiData object to retrieve any value stored in it.

Here is a link to source code which does exactly this but with Flutter api json data.

https://github.com/TheKetan2/stackoverflow_answers/blob/master/lib/flutter_api_example.dart