title: How to map json to class models?
body: <p>I've been trying to work with jsons but my way was really stupid and had to code a lot more line without a model. So I want to learn how to map to models and how to use them.</p>
  
  <p>This is the model:</p>
  
  <pre><code>namespace Chino.Models
  {
      public class Event
      {
          public string display_html { get; set; }
          public string beatmap_id { get; set; }
          public string beatmapset_id { get; set; }
          public string date { get; set; }
          public string epicfactor { get; set; }
      }
  
      public class Profile
      {
          public string user_id { get; set; }
          public string username { get; set; }
          public string join_date { get; set; }
          public string count300 { get; set; }
          public string count100 { get; set; }
          public string count50 { get; set; }
          public string playcount { get; set; }
          public string ranked_score { get; set; }
          public string total_score { get; set; }
          public string pp_rank { get; set; }
          public string level { get; set; }
          public string pp_raw { get; set; }
          public string accuracy { get; set; }
          public string count_rank_ss { get; set; }
          public string count_rank_ssh { get; set; }
          public string count_rank_s { get; set; }
          public string count_rank_sh { get; set; }
          public string count_rank_a { get; set; }
          public string country { get; set; }
          public string total_seconds_played { get; set; }
          public string pp_country_rank { get; set; }
          public List&lt;Event&gt; events { get; set; }
      }
  }
  </code></pre>
  
  <p>And this is the code:</p>
  
  <pre><code>string url = $"http://osu.ppy.sh/api/get_user?k={k}&amp;u={username}";
                  using (HttpClient client = new HttpClient())
                  {
                      string json = await client.GetStringAsync(url);
                      Profile profile = JsonConvert.DeserializeObject&lt;Profile&gt;(json);
  
  
                      embed.WithThumbnailUrl($"https://a.ppy.sh/{profile.user_id}");
                      embed.WithAuthor($"{username} #{profile.pp_rank}, {profile.pp_raw}PP", Context.Guild.CurrentUser.GetAvatarUrl(), $"https://osu.ppy.sh/users/{user_id}");
                      embed.WithDescription($"Join date:{profile.join_date}\nCountry:{profile.country} #{profile.pp_country_rank}\nAccuray:{double.Parse(profile.accuracy):F2}%\nPlaycount:{profile.playcount}");                 
                      embed.WithColor(154, 255, 0);
                      await ReplyAsync($"", false, embed.Build());
                      client.Dispose();
                  }
  </code></pre>
  
  <p>I made the model with json2csharp and so I don't think the problem is in the model.</p>
  
  <pre><code>[{"user_id":"7794035","username":"Citrom","join_date":"2016-01-20 17:21:57","count300":"5285260","count100":"992638","count50":"84329","playcount":"35721","ranked_score":"7215598829","total_score":"33075404306","pp_rank":"67927","level":"100.061","pp_raw":"3602.27","accuracy":"94.95156860351562","count_rank_ss":"21","count_rank_ssh":"6","count_rank_s":"292","count_rank_sh":"408","count_rank_a":"569","country":"HU","total_seconds_played":"2090643","pp_country_rank":"295","events":[{"display_html":"&lt;img src='\/images\/B_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #666 on &lt;a href='\/b\/1706256?m=0'&gt;Sangatsu no Phantasia - Collage (TV Size) [CRN's Insane]&lt;\/a&gt; (osu!)","beatmap_id":"1706256","beatmapset_id":"805425","date":"2019-08-28 20:14:27","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/A_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #282 on &lt;a href='\/b\/2025119?m=0'&gt;Kajiura Yuki - Administrator [Insane]&lt;\/a&gt; (osu!)","beatmap_id":"2025119","beatmapset_id":"967707","date":"2019-08-28 19:47:15","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/C_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #799 on &lt;a href='\/b\/2025119?m=0'&gt;Kajiura Yuki - Administrator [Insane]&lt;\/a&gt; (osu!)","beatmap_id":"2025119","beatmapset_id":"967707","date":"2019-08-28 19:44:43","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/SH_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #100 on &lt;a href='\/b\/1399403?m=0'&gt;Poppin'Party - Natsu no Don! [Hard]&lt;\/a&gt; (osu!)","beatmap_id":"1399403","beatmapset_id":"653523","date":"2019-08-28 19:20:41","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/SH_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved &lt;b&gt;rank #23&lt;\/b&gt; on &lt;a href='\/b\/2085890?m=0'&gt;Day6 - Man in a movie [Hard]&lt;\/a&gt; (osu!)","beatmap_id":"2085890","beatmapset_id":"745457","date":"2019-08-28 15:43:27","epicfactor":"2"},{"display_html":"&lt;img src='\/images\/D_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #327 on &lt;a href='\/b\/1774124?m=0'&gt;Haywyre - Insight [Normal]&lt;\/a&gt; (osu!)","beatmap_id":"1774124","beatmapset_id":"848400","date":"2019-08-28 13:09:00","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/D_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #363 on &lt;a href='\/b\/1774124?m=0'&gt;Haywyre - Insight [Normal]&lt;\/a&gt; (osu!)","beatmap_id":"1774124","beatmapset_id":"848400","date":"2019-08-28 13:02:59","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/SH_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #604 on &lt;a href='\/b\/163117?m=0'&gt;Shihori - Magic Girl !! [Hard]&lt;\/a&gt; (osu!)","beatmap_id":"163117","beatmapset_id":"53519","date":"2019-08-28 11:30:24","epicfactor":"1"},{"display_html":"&lt;img src='\/images\/SH_small.png'\/&gt; &lt;b&gt;&lt;a href='\/u\/7794035'&gt;Citrom&lt;\/a&gt;&lt;\/b&gt; achieved rank #236 on &lt;a href='\/b\/1102401?m=0'&gt;TRUE - Soundscape [Kencho's Hard]&lt;\/a&gt; (osu!)","beatmap_id":"1102401","beatmapset_id":"508222","date":"2019-08-28 11:17:52","epicfactor":"1"}]}]
  </code></pre>
  
  <p>And when I use this I get this error message:</p>
  
  <blockquote>
    <p>Cannot deserialize the current JSON array (e . g. [1.2.3]) into type ' Chino . Models . Profile' because the type requires a JSON object (e . g. {"name":"value"}) to desrialize correctly. To fix this error either change the JSON to a JSON object (e. g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e . g. I Collection. I List) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. </p>
    
    <p>Path '', line 1. position 1. </p>
    
    <p>Object reference not set to an instanceof an object.</p>
  </blockquote>