flutter type 'String' is not a s

2024-08-08  本文已影响0人  myjourney

报错

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) {
...

参考链接

上一篇 下一篇

猜你喜欢

热点阅读