【问题标题】:Json String to Map<> or List映射 <> 或列表的 Json 字符串
【发布时间】:2019-02-17 13:02:21
【问题描述】:

我有一个 json 存储为字符串,如下所示

String json="[{"name":"a","id",1},{"name":"b","id",2},{"name":"c","id",3}]";

我的问题如何将其编码为地图或列表以访问键并使用值?

【问题讨论】:

  • 这已经是一个地图列表。 String 类型无效。应该是List&lt;Map&lt;String,dynamic&gt;&gt;
  • 检查我将其存储为字符串的编辑
  • 这仍然是无效的;p 因为你不能在由" 分隔的字符串中包含" 而不转义内部"

标签: dart flutter


【解决方案1】:

您需要先对值进行 JSON 解码

import 'dart:convert';

final decoded = jsonDecode(json);
print(decoded[0]['name']); // just one example

【讨论】:

    猜你喜欢
    • 2014-09-16
    • 2017-05-21
    • 2021-05-10
    • 1970-01-01
    • 2018-02-24
    • 2021-08-15
    • 2018-11-15
    • 1970-01-01
    相关资源
    最近更新 更多