my obj is:
Map myJSON = {
"name": {"first":"foo","last":"bar"},
"age":31, "city":"New York"
};
I want to replace it with the new output Ex:
String myJSON = '{"name":{"first":"foo","last":"bar"}, "age":31, "city":"New York"}';
Using toString() method The string representation of a map consists of a list of key-value pairs enclosed within curly braces, where the adjacent pairs are delimited by a comma followed by a single space and each key-value pair is separated by the equals sign ( = ). i.e., {K1=V1, K2=V2, ..., Kn=Vn} .
map() is known to belong to the array prototype. In this step you will use it to convert a string to an array. You are not developing the method to work for strings here.
Use the convert
class
import 'dart:convert';
Convert string to Map
json.decode(stringData);
Convert Map to string
json.encode(mapData);
String jsonString = jsonEncode(myJSON);
print(jsonString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With