当前位置:网站首页>Shuttle JSON, list, map inter transfer

Shuttle JSON, list, map inter transfer

2022-06-25 09:43:00 Moon Spring

Flutter Json turn List、Map It's simple , We can go through dart:convert The built-in JSON decoder json.decode() To achieve

Json turn List
// One JSON Format string
String jsonStr = ‘[{“name”:“ Zhang San ”},{“name”:“ Li Si ”}]’;
// take JSON String to List
List list = json.decode(jsonStr);
// Output the name of the first user
print(list[0][“name”]);

List turn Json
String jsonStringA = json.encode(list);
print(jsonStringA);

Json turn Map
// One JSON Format string
String jsonStr = ‘{“name”: “ Wang Wu ”,“address”: “ Dongcheng District ”}’;
// take JSON String to List
Map<String, dynamic> map = json.decode(jsonStr);
// Output
print(‘ full name : ${map[‘name’]}’);
print(‘ Address : ${map[‘address’]}’);

Map turn Json
String jsonStringB = json.encode(map);
print(jsonStringB);

Reprint . This article is the original article of blogger mazhiwu ,
Link to the original text :https://blog.csdn.net/ruoshui_t/article/details/103793190

原网站

版权声明
本文为[Moon Spring]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200549006223.html