将字符串转换为dart中的映射 [英] converting string to map in dart

查看:128
本文介绍了将字符串转换为dart中的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字符串转换为map。

I wanted to convert a string to map.

String value = "{first_name : fname,last_name : lname,gender : male, location : { state : state, country : country, place : place} }"

进入

Map = {
first_name : fname,
last_name : lname,
gender : male,
location = {
  state : state, 
  country : country, 
  place : place
 }
}

如何将字符串转换为 map< String,dynamic> 由字符串,整数,对象和布尔值组成?

How do I convert the string into a map<String, dynamic> where the value consists of string, int, object, and boolean?

我想将字符串保存到文件中并从文件中获取数据。

I wanted to save the string to a file and obtain the data from the file.

推荐答案

不可能。

如果您可以将字符串更改为有效的JSON,则可以使用

If you can change the string to valid JSON, you can use

import 'dart:convert';
...
Map valueMap = json.decode(value);
// or
Map valueMap = jsonDecode(value);

字符串必须看起来像

{"first_name" : "fname","last_name" : "lname","gender" : "male", "location" : { "state" : "state", "country" : "country", "place" : "place"} }

这篇关于将字符串转换为dart中的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆