LoginSignup
5
3

More than 1 year has passed since last update.

【Dart】json文字列とMapの変換

Last updated at Posted at 2022-02-16

Dartでjson文字列とMapの相互変換処理です。

備忘録として残しておきます。

  • Dart: 2.15
import 'dart:convert' as convert;

void main() {
  final map1 = {
    "name": "hoge",
    "age": 20
  };
  
  // Map => json文字列
  final json = convert.json.encode(map1);
  print(json); // {"name":"hoge","age":20}

  // json文字列 => Map
  final map2 = convert.json.decode(json) as Map<String, dynamic>;
  print(map2); // {name: hoge, age: 20}
}

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3