Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json _CastError(type';"InternalLinkedHashMap<;String,dynamic>;';不是类型转换中的List<;dynamic>;';类型的子类型)_Json_Flutter_Dart_Sharedpreferences_Sqflite - Fatal编程技术网

Json _CastError(type';"InternalLinkedHashMap<;String,dynamic>;';不是类型转换中的List<;dynamic>;';类型的子类型)

Json _CastError(type';"InternalLinkedHashMap<;String,dynamic>;';不是类型转换中的List<;dynamic>;';类型的子类型),json,flutter,dart,sharedpreferences,sqflite,Json,Flutter,Dart,Sharedpreferences,Sqflite,想再问一次。。。尝试实现存储在本地数据库中的数据API。。。 JSON API的形式对象中有一个JSON数组。。。希望将数据从API加载到本地数据库时出错。。。大体上这是一个错误,因为“错误的模型或什么 Api服务 class MealApiProvider { Future<List<Categories>> getAllMeal() async { var url = "https://www.themealdb.com/api/json/v1/1/cat

想再问一次。。。尝试实现存储在本地数据库中的数据API。。。 JSON API的形式对象中有一个JSON数组。。。希望将数据从API加载到本地数据库时出错。。。大体上这是一个错误,因为“错误的模型或什么

Api服务

class MealApiProvider {
  Future<List<Categories>> getAllMeal() async {
    var url = "https://www.themealdb.com/api/json/v1/1/categories.php";
    Response response = await Dio().get(url);
    print("Hasil Respon ${response.data}");
    return (response.data as List).map((employee) {
      print('Inserting $employee');
      DBProvider.db.insertMeals(Categories.fromJson(employee));
    }).toList();
  }
}
错误

返回(response.data作为列表).map((员工)


您的回复一开始就包含map! 试试这个

class MealApiProvider {
  Future<List<Categories>> getAllMeal() async {
    var url = "https://www.themealdb.com/api/json/v1/1/categories.php";
    Response response = await Dio().get(url);
    print("Hasil Respon ${response.data}");
    //***Change below line****
    return (response.data['categories'] as List).map((employee) {
      print('Inserting $employee');
      DBProvider.db.insertMeals(Categories.fromJson(employee));
    }).toList();
  }
}
class MealApiProvider{
Future getAllMine()异步{
变量url=”https://www.themealdb.com/api/json/v1/1/categories.php";
Response=wait Dio().get(url);
打印(“Hasil Respon${response.data}”);
//***换行****
return(response.data['categories']作为列表).map((雇员){
打印(“插入$employee”);
DBProvider.db.insertfines(Categories.fromJson(employee));
}).toList();
}
}
而不是

class MealApiProvider {
  Future<List<Categories>> getAllMeal() async {
    var url = "https://www.themealdb.com/api/json/v1/1/categories.php";
    Response response = await Dio().get(url);
    print("Hasil Respon ${response.data}");
    //*** I change the below line !
    return (response.data as List).map((employee) {
      print('Inserting $employee');
      DBProvider.db.insertMeals(Categories.fromJson(employee));
    }).toList();
  }
}
class MealApiProvider{
Future getAllMine()异步{
变量url=”https://www.themealdb.com/api/json/v1/1/categories.php";
Response=wait Dio().get(url);
打印(“Hasil Respon${response.data}”);
//***我更改下面的行!
返回(response.data作为列表).map((员工){
打印(“插入$employee”);
DBProvider.db.insertfines(Categories.fromJson(employee));
}).toList();
}
}

嘿,你在数组中使用了错误的数据类型,数组的使用列表和JSON对象的使用映射。请尝试一下,它会起作用。我更改了哪些代码?我不知道,但在看到你的响应后可能会更改。请看我已更新的图片
class MealApiProvider {
  Future<List<Categories>> getAllMeal() async {
    var url = "https://www.themealdb.com/api/json/v1/1/categories.php";
    Response response = await Dio().get(url);
    print("Hasil Respon ${response.data}");
    //***Change below line****
    return (response.data['categories'] as List).map((employee) {
      print('Inserting $employee');
      DBProvider.db.insertMeals(Categories.fromJson(employee));
    }).toList();
  }
}
class MealApiProvider {
  Future<List<Categories>> getAllMeal() async {
    var url = "https://www.themealdb.com/api/json/v1/1/categories.php";
    Response response = await Dio().get(url);
    print("Hasil Respon ${response.data}");
    //*** I change the below line !
    return (response.data as List).map((employee) {
      print('Inserting $employee');
      DBProvider.db.insertMeals(Categories.fromJson(employee));
    }).toList();
  }
}