The best way to parse a JSON in Dart The best way to parse a JSON in Dart dart dart

The best way to parse a JSON in Dart


Simply use json of the dart:convert package. Here is an example :

import 'dart:convert';main() {  final myJsonAsString = '{"a": 1, "b": "c"}';  final decoded = json.decode(myJsonAsString);  ....}

See Parsing JSON for more details.


in my case

JSON.decode

didn't work.

Instead I had to use :

import 'dart:convert' as JSON;final json=JSON.jsonDecode(myJsonAsString);


Here is my solution :) At first, you need to import the convert package:

import 'dart:convert';var res = json.decode(response.body);

then you can get values by key, like below:

print(res["message"]);