Convert between json, map and list in flutter
json to List
String jsonStr = '[{"name":"budaye", "city":"北京"},{"name":"卜大爷", "city":"北京"}]';
List list = json.decode(jsonStr);
json to map
In the list in the above example, Map objects are stored:
//接着上例:
for(int i=0;i<list.length;i++){
Map map = list[i];
}
If the json object is not a json array:
String jsonStr = '{"name":"budaye", "city":"北京"}';
Map<String, dynamic> map = json.decode(jsonStr);
List to json
String jsonStr = json.encode(list);
Map to json
String jsonStr = json.encode(map);
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"