小编Nad*_*eid的帖子

Dart - 类型“String”不是类型“Iterable<dynamic>”的子类型

我正在尝试在 dart 中解析本地 JSON 文件并显示其值。

用户.json

[
    {
        "id": 1,
        "name": "Greg",
        "imageUrl": "assets/images/greg.jpg"
    },
    {
        "id": 2,
        "name": "James",
        "imageUrl": "assets/images/james.jpg"
    }
]
Run Code Online (Sandbox Code Playgroud)

这是我的 chats.json

[
    {
        "sender": "james",
        "time": "5:30 PM",
        "text": "Hey, how's it going? What did you do today?",
        "isLiked": false,
        "unread": true
    },
    {
        "sender": "olivia",
        "time": "4:30 PM",
        "text": "Hey, how's it going? What did you do today?",
        "isLiked": true,
        "unread": false
    }
]
Run Code Online (Sandbox Code Playgroud)

这是我的消息类

class Message {
  final User sender;
  final String time; …
Run Code Online (Sandbox Code Playgroud)

json dart flutter

5
推荐指数
1
解决办法
1万
查看次数

无法读取javascript变量

在控制台中,我似乎无法记录"男性"或"女性"的值.应该是这样的console.log(choice[0].a).它不记录变量的值string.以下是我的尝试,谢谢你的时间.

<html>
    <head>
        <script type="text/javascript">
            var string = "";
            var randoml = "ab";
            while (string.length < 1) {
              string += randoml[Math.floor(Math.random() * randoml.length)];
            } 
            console.log(string);
           data = '[{"a" : "male", "b" : "female"}]';
           var choice = JSON.parse(data);
           console.log(choice[0].string); 
        </script>
    </head>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript variables json

-1
推荐指数
1
解决办法
70
查看次数

标签 统计

json ×2

dart ×1

flutter ×1

html ×1

javascript ×1

variables ×1