【问题标题】:how to convert a JSON data into map in Flutter?如何在 Flutter 中将 JSON 数据转换为地图?
【发布时间】:2021-01-05 12:09:23
【问题描述】:

我的 JSON 数据是这样的:

{
notification:{
     title: flutter fcm, 
     body: i got a firebase notification
              }, 
 data:{
     myKey: myValue
      }
}

我应该如何将它转换成地图??

这是在 firebase 推送通知的 onMessage() 回调上打印的值。它正在我的控制台上打印。我想把它转换成地图。这个 JSON 数据的 runtimeType 是 String。

【问题讨论】:

    标签: string firebase flutter dictionary push-notification


    【解决方案1】:

    我们可以使用dart:convert 包和json.decode 方法将JSON String 转换为Map

    import 'dart:convert';
    
    final Map<String, dynamic> jsonData = json.decode(jsonData);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 2022-11-12
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多