美文网首页
flutter type 'String' is not a s

flutter type 'String' is not a s

作者: myjourney | 来源:发表于2024-08-08 17:46 被阅读0次

报错

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

参考链接

相关文章

网友评论

      本文标题:flutter type 'String' is not a s

      本文链接:https://www.haomeiwen.com/subject/vzchkjtx.html