title: Flutter Json Encode List
body: <p>How to encode list to json?</p>
  
  <p>This is my class for Json.</p>
  
  <pre><code>class Players{
    List&lt;Player&gt; players;
  
    Players({this.players});
  
    factory Players.fromJson(List&lt;dynamic&gt; parsedJson){
  
      List&lt;Player&gt; players = List&lt;Player&gt;();
      players = parsedJson.map((i)=&gt;Player.fromJson(i)).toList();
  
      return Players(
        players: players,
      );
    }
  }
  
  class Player{
    final String name;
    final String imagePath;
    final int totalGames;
    final int points;
  
    Player({this.name,this.imagePath, this.totalGames, this.points});
  
    factory Player.fromJson(Map&lt;String, dynamic&gt; json){
  
      return Player(
        name: json['name'],
        imagePath: json['imagePath'],
        totalGames: json['totalGames'],
        points: json['points'],
      );
    }
  }
  </code></pre>
  
  <p>I managed to decode with fromJson, the result is in List. Now that I have another player to add in json and want to encode the list to json, have no idea to do it. It result always failed.</p>
  
  <pre><code>var json = jsonDecode(data);
  List&lt;Player&gt; players = Players.fromJson(json).players;
  Player newPlayer = Player(name: _textEditing.text,imagePath: _imagePath,totalGames: 0,points: 0);
  players.add(newPlayer);
  String encode = jsonEncode(players.players);
  </code></pre>
  
  <p>What do I need to add on Players or Player?</p>