title: Mapping JSON into Class Objects
body: <p>I am trying to map my JSON file into a class object, and then update the cards based on the newly received JSON.</p>
  
  <p>My JSON structure is like this </p>
  
  <pre><code> {
          "$class": "FirstCard",
          "id": "1",
          "description": "I am card number one",
          "Role": "attack",
          "score": 0,
          "tag": [
              "string"
          ],................}
  </code></pre>
  
  <p>my Class looks like this:</p>
  
  <pre><code>  class CardInfo {
    //Constructor
    String id;
    String description;
    String role;
    int score;
  
  }
  </code></pre>
  
  <p>How can I map the values in my JSON file into the fields of objects created from CardInfo class?</p>
  
  <p><strong>Update</strong></p>
  
  <p>the following trial prints null at <strong>ci.description</strong>, does this mean the object was never created ? </p>
  
  <pre><code>const jsonCodec = const JsonCodec
  _loadData() async {
    var url = 'myJsonURL';
    var httpClient  = createHttpClient();
    var response =await httpClient.get(url);
    print ("response" + response.body);
    Map cardInfo = jsonCodec.decode(response.body);
    var ci = new CardInfo.fromJson(cardInfo);
    print (ci.description); //prints null
  }
  </code></pre>
  
  <p><strong>Update2</strong> </p>
  
  <p>Printing cardInfo gives the following:</p>
  
  <blockquote>
    <p>{$class: FirstCard, id: 1, description: I am card number one,........}</p>
  </blockquote>
  
  <p>Note that it resembles the original JSON but without the double quotes on string values. </p>