Home > Mobile >  how to filter Json data and use other methods | function | classes? How get Json data into list?
how to filter Json data and use other methods | function | classes? How get Json data into list?

Time:02-11

Future<List<AdMob>>getData() async {


 final String url =
      "https://raw.githubusercontent.com/awais939869/AdsJson/main/speedifypro.json";
  http.Response response = await http.get(Uri.parse(url));
  // http.Response response = await http.get(Uri.parse("https://raw.githubusercontent.com/Hammad46/app/main/admob.json"));

  var jsonObject = json.decode(response.body);
 List <dynamic> data = (jsonObject as Map<String, dynamic>)['AdMob'];

 List <AdMob> listData = [];
 for (int i=0; i<data.length; i  )
    listData.add(AdMob.fromJson(data[i]));
 return listData;
}

ERROR E/flutter ( 6315): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List'

JSON data {

"AdMob": { "Banner": "true", "Interstitial": "true" } }

CodePudding user response:

AdMob is not a List. it's a map. so if you want your code to work without problem your JSON should be like following:

{
    "AdMob": [
        {
            "Banner": "true",
            "Interstitial": "true"
        }
    ]
}
  • Related