我正在尝试获取 api,我可以在控制台中打印 api 响应。但是,当我收到对模型类的响应时,控制台显示如下错误
E/flutter(9292):[错误:flutter/lib/ui/ui_dart_state.cc(157)]未处理的异常:类型“String”不是“index”的“int”类型的子类型
模型.dart
class CategoryDishes {
final String dishId;
final String dishName;
final String dishDescription;
CategoryDishes(
{this.dishId,
this.dishName,
this.dishDescription,});
factory CategoryDishes.fromJson(Map<String, dynamic> json) {
return CategoryDishes(
dishId: json['dish_id'],
dishName: json['dish_name'],
dishDescription: json['dish_description'],
}
static Resource<List<CategoryDishes>> get all {
return Resource(
url: Constants.FOOD_API_URL,
parse: (response) {
final result = json.decode(response.body.toString());
print(response);
Iterable list = result['category_dishes'];
return list.map((model) => CategoryDishes.fromJson(model)).toList();
});
}
}
Run Code Online (Sandbox Code Playgroud)
web_service.dart
class Resource<T> {
final String url;
T Function(Response response) parse;
Resource({this.url, this.parse});
}
class Webservice …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用 FFmpeg 修剪视频的应用程序。当修剪过程已经开始并且我取消它时,FFmpeg 完全终止。如何仅通过终止当前工作进程来实现?
/* define PID */
try {
String pid = ffmpeg.toString();
pid = pid.substring(pid.indexOf("[") + 1, pid.indexOf("]"));
Process process = Runtime.getRuntime().exec("kill -2 " + pid);
process.waitFor();
ffmpeg.wait();
} catch (IOException | InterruptedException e) {
Log.e(TAG, "kill_ffmpeg: exception failed ",e );
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
这是我现在一直在使用的代码。当此代码唤醒时,活动将重新启动,但索引越界除外。
这是我使用 FFmpeg Here实现视频编辑功能的库
这个 FFmpeg 库中有一个方法叫做killRunningProcess(). 当我使用此方法时,显示一个名为cannot resolve method killRunningProcess()
如何在调用特定代码时在没有内存泄漏和不使应用程序崩溃的情况下杀死进程?
我有一个返回一些数据的api。我只需要从 api 中获取菜肴数据。问题是当我从 api 响应中获取数据时,第一道菜数据仅保存到iteratable list.
编辑
我无法从可迭代列表中获取数据
api 如下所示
[
{
"restaurant_name": "Cafe",
"restaurant_image": "http://restaurants.unicomerp.net/images/Restaurant/1010000001.jpg",
"table_id": "1",
"table_name": "Table 01",
"branch_name": "Cafe",
"nexturl": "http://snapittapp.snapitt.net/api/menu/10/?org=1010000001&branch_id=1000000001&limit=10&offset=20&lang=en",
"table_menu_list": [
{
"menu_category": "Salads and Soup",
"menu_category_id": "11",
"menu_category_image": "http://restaurants.unicomerp.net/images/Restaurant/Item/ItemGroup_11.jpg",
"nexturl": "http://snapittapp.snapitt.net/api/menu/20/?org=1010000001&branch_id=1000000001&menuCat=11&limit=10&offset=20&lang=en",
"category_dishes": [
{
"dish_id": "100000001",
"dish_name": "Spinach Salad",
"dish_price": 7.95,
"dish_image": "http://restaurants.unicomerp.net//images/Restaurant/1010000001/Item/Items/100000001.jpg",
"dish_currency": "SAR",
"dish_calories": 15,
"dish_description": "Fresh spinach, mushrooms, and hard-boiled egg served with warm bacon vinaigrette",
"dish_Availability": true,
"dish_Type": 2,
"nexturl": "http://snapittapp.snapitt.net/api/menu/30/?org=1010000001&branch_id=1000000001&menuItem=100000001&limit=10&offset=20&lang=en",
"addonCat": [
{
"addon_category": "Spicy/Non-Spicy",
"addon_category_id": …Run Code Online (Sandbox Code Playgroud) 当我得到一个 api 时,控制台显示如下错误
E/flutter (10838): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:FormatException: Unexpected character (at character 1)
E/flutter (10838):“响应”的实例
E/扑(10838):^
E/扑(10838):
这就是我获取 api 的方式
Future _fetchPost() async {
http.Response response = await http.get(url);
if (response.statusCode == 200) {
print(response.statusCode);
print(json.decode(response.body));
} else {
print(response.statusCode);
}
setState(() {
String jsonsDataString = response.toString();
_data = jsonDecode(jsonsDataString);
print(_data.toString());
});
return "Success";
}
Run Code Online (Sandbox Code Playgroud)
状态码返回 200 和一些 api
I/扑(10838):200
I /扑(10838):[{restaurant_id:1010000001,RESTAURANT_NAME:咖啡,restaurant_image: HTTP://.unicomerp./1010000001.jpg,table_id的:1,表名:利雅德-E 01,branch_name:我CAH,nurl: HTTP ://snapittaitt.net/api/menu/10/有机= 000001&branch_id = 100it = 10&偏移量= 20&郎=恩?,table_menu_list:[{menu_category:沙拉和汤,menu_category_id:11,menu_category_image: http://res.net/ iRet/Item/ItemGroup_11.jpg , nexturl: http://snapittappt.net/api/menu/20/?org=1010000001&branch_id=10000001&menuCat=it=10&offset=20&lang=en , category_dishes: …