flutter print json
To print a JSON object in Flutter, you can use the print()
function along with the jsonEncode()
function from the dart:convert
library. Here's an example:
import 'dart:convert';
void main() {
Map<String, dynamic> jsonData = {
'name': 'John Doe',
'age': 30,
'email': '[email protected]'
};
String jsonString = jsonEncode(jsonData);
print(jsonString);
}
In this example, we have a jsonData
map that represents a JSON object with three key-value pairs: name
, age
, and email
. We then use the jsonEncode()
function to convert this map into a JSON string. Finally, we print the JSON string using the print()
function.
When you run this code, the JSON string will be printed to the console. The output will look something like this:
{"name":"John Doe","age":30,"email":"[email protected]"}
Please note that you need to import the dart:convert
library to use the jsonEncode()
function.