这是我如何处理请求:
http.get(Uri.parse("${Constants.BASE_URL}categories/SubWithSubSub/${itemModel.id}"), headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest',
'lang': Constants.LANG
}).then((secondResponse) async {
for (var item in secondResponse.body){ //error in this line
print(item);
}
});
这是我的回复:
{"success":true,"data":[{"id":149,"name":"Honey","subSub":{"viewAll":false,"data":[]}},{"id":150,"name":"Herbs","subSub":{"viewAll":false,"data":[]}}]}
我看到这个错误:
The type 'String' used in the 'for' loop must implement Iterable
答案 0 :(得分:0)
我猜你在解码响应体中的字符串
试试这个
var responseList = jsonDecode(secondResponse.body);
for (var item in responseList ){ //error in this line
print(item);
}