【发布时间】:2022-01-03 08:13:33
【问题描述】:
我的 api 有这个 post 请求,它需要一个 json 对象数组,例如:
[{
"x": 1,
"y": 1
}]
我的功能:
Future<String> deleteObstacle(String server, int x, int y) async {
final response =
await http.delete(Uri.parse('$server/admin/obstacles/'), headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}, body: [
jsonEncode(<String, int>{"x": x, "y": y})
]);
if (response.statusCode == 200) {
Map<String, dynamic> launchResponse = jsonDecode(response.body);
return launchResponse['response'];
} else {
throw Exception("ERROR Attempting to Delete obstacle");
}
}
}
抛出错误:
"Expected a value of type 'int', but got one of type 'String'
我不知道如何映射那个身体,我尝试了很多东西。哪种方法更好?
编辑:
完整的堆栈跟踪here
【问题讨论】:
-
错误指的是什么?你能发布堆栈跟踪吗?
-
@ScottHunter 发布了堆栈跟踪。基本上当用户想要从世界中删除一个对象时调用该函数。
标签: flutter