报错
type 'String' is not a subtype of type 'int' of 'index'
情况:
在解析json数据的时候,一直报错type 'String' is not a subtype of type 'int' of 'index' ,但是呢,打印出来看数据也没错。
for (var item in conversationList) {
var aiMemberIds = itemJson["aiMemberIds"];
{"conversationId":"0:1:20:358638279299432469","hasMore":true,"unreadCount":14,"conversationShortId":7375094393822888254,"aiMemberIds":20}
代码就崩溃到var aiMemberIds = itemJson["aiMemberIds"];这一行。
分析:
json解析的时候出错了,加一个解析
itemJson = json.decode(itemJson);
整体的代码就是:
for (var itemJson in conversationList) {
itemJson = json.decode(itemJson);
var aiMemberIds = itemJson["aiMemberIds"];
if (aiMemberIds != null &&
aiMemberIds != 100001 &&
aiMemberIds != 100002) {
...