title: Xamarin Forms Json Desrialization
body: <p>I want to deserialize a JSON coming from a web service, but for some reason I am getting an exception. I searched every question related to this topic but I did not find anything related to this exception. What might me the problem? here is the exception:</p>
  <pre><code>Newtonsoft.Json.JsonSerializationException: 'Unexpected token while deserializing object: EndObject. Path '', line 1, position 243.'
  </code></pre>
  <p>Here is my deserialize method:</p>
  <pre><code>        public async Task&lt;LoginApiResponse&gt; AuthenticateUserAsync(string username, string password)
      {
          
        //  try
        //  {
              LoginApiRequest loginRequest = new LoginApiRequest()
              {
                  Username = username,
                  Password = password
              };
  
              // serialize object to json
              var content = new StringContent(JsonConvert.SerializeObject(loginRequest), Encoding.UTF8, &quot;application/json&quot;);
  
              var response = await Client.PostAsync(Constants.LOGIN_URI, content);
              response.EnsureSuccessStatusCode();
              // get the data on success and serialize it from json
              using (var stream = await response.Content.ReadAsStreamAsync())
              using (var reader = new StreamReader(stream))
              using (var json = new JsonTextReader(reader))
              {
                  System.Diagnostics.Debug.Write(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; &quot; + Serializer.Deserialize&lt;LoginApiResponse&gt;(json));
                  return Serializer.Deserialize&lt;LoginApiResponse&gt;(json);
              }
         // }
    /*      catch (Exception ex)
          {
              return null;
          }*/
      }
  </code></pre>
  <p>here is the Request model:</p>
  <pre><code>    public class LoginApiRequest
  {
      [JsonProperty(&quot;Username&quot;)]
      public string Username { get; set; }
  
      [JsonProperty(&quot;Password&quot;)]
      public string Password { get; set; }
      public LoginApiRequest() { }
  }
  </code></pre>
  <p>here is the Response Model:</p>
  <pre><code>public class LoginApiResponse : MessageStatus
  {
      [JsonProperty(&quot;Data&quot;)]
      public User Data { get; set; }
      public LoginApiResponse() { }
  }
  </code></pre>
  <p>here is the User model:</p>
  <pre><code>    public class User
  {
      [JsonProperty(&quot;Address&quot;)]
      public string Address { get; set; }
  
      [JsonProperty(&quot;BloodType&quot;)]
      public string BloodType { get; set; }
      [JsonProperty(&quot;ConfirmPassword&quot;)]
      public string ConfirmPassword { get; set; }
  
      [JsonProperty(&quot;CustomerID&quot;)]
      public string CustomerID { get; set; }
  
      [JsonProperty(&quot;DOB&quot;)]
      public string DOB { get; set; }
  
      [JsonProperty(&quot;Email&quot;)]
      public string Email { get; set; }
  
      [JsonProperty(&quot;ID&quot;)]
      public int? ID { get; set; }
  
      [JsonProperty(&quot;IsActive&quot;)]
      public bool IsActive { get; set; }
  
      [JsonProperty(&quot;Name&quot;)]
      public string Name { get; set; }
  
      [JsonProperty(&quot;Password&quot;)]
      public string Password { get; set; }
  
      [JsonProperty(&quot;Phone&quot;)]
      public string Phone { get; set; }
  
      [JsonProperty(&quot;UserRoleID&quot;)]
      public int? UserRoleID { get; set; }
  
      [JsonProperty(&quot;Username&quot;)]
      public string Username { get; set; }
  
      public User() { }
  }
  </code></pre>
  <p>and here is the the messagestatus:</p>
  <pre><code>    public class MessageStatus
  {
      [JsonProperty(&quot;Message&quot;)]
      public string Message { get; set; }
  
      [JsonProperty(&quot;Status&quot;)]
      public int Status { get; set; }
      public MessageStatus() { }
  }
  </code></pre>
  <p>and finally here is the json:</p>
  <pre><code>{
      &quot;Message&quot;: null,
      &quot;Status&quot;: 1,
      &quot;Data&quot;: {
          &quot;Address&quot;: &quot;Beirut&quot;,
          &quot;BloodType&quot;: null,
          &quot;ConfirmPassword&quot;: null,
          &quot;CustomerID&quot;: null,
          &quot;DOB&quot;: null,
          &quot;Email&quot;: null,
          &quot;ID&quot;: 22,
          &quot;IsActive&quot;: true,
          &quot;Name&quot;: &quot;tg&quot;,
          &quot;Password&quot;: &quot;123456&quot;,
          &quot;Phone&quot;: &quot;03708424&quot;,
          &quot;UserRoleID&quot;: 1,
          &quot;Username&quot;: &quot;tg&quot;
      }
  }
  </code></pre>