How to Solve Flutter Expected a value of type 'List<dynamic>', but got one of type 'JsonMap'

Issue

Flutter Expected a value of type ‘List’, but got one of type ‘_jsonMap’

When i’m did this same with localhost it worked fine but when i do this same with hosting it give me this error.from api side is working api is sending the data.but something wrong.
enter image description here

//Future is n object representing a delayed computation.
Future<List<Homes>> downloadJSON() async {
  final jsonEndpoint = "https://homeshouse.000webhostapp.com/get.php";
  
  final response = await get(Uri.parse(jsonEndpoint));

  if (response.statusCode == 200) {
    List homelist = json.decode(response.body);
    return homelist.map((home) => new Homes.fromJson(home)).toList();
  } else
    throw Exception('We were not able to successfully download the json data.');
}

please help i stucked here from last 2 days and i’m not getting this

Solution

 if (response.statusCode == 200) {
    final json = "[" + response.body + "]";
    List homelist = (jsonDecode(json) as List<dynamic>) ;

this is works for me:-
enter link description here

Answered By – MindCoder

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *