【发布时间】:2019-08-23 02:49:34
【问题描述】:
我在运行时收到以下错误我正在执行 http 调用并返回 json。
"_TypeError (类型'List'不是类型'() => void'的子类型)"
这是我的代码
class _ForumPostsState extends State<ForumPosts> {
List data;
String categoryID = 'D64D0737-746D-4562-8C10-6445F4069A92';
Future<String> getPostsByCategory() async {
var response = await http.post(
Uri.encodeFull("http://api/ForumPostsByCategory"),
headers: {"Content-Type": "application/json",
'Accept': 'application/json',},
body: json.encode({'categoryID' : categoryID }));
this.setState(
data = json.decode(response.body)
);
print(data[1]["title"]);
return "Success!";
}
在这一行抛出错误
data = json.decode(response.body)
在调试时我注意到 JSON 在那里,它只是 data = json.decode 调用上的错误。
【问题讨论】: