title: Angular4 TypeScript JsonReaderException
body: <p>I have table with 1 or many records which is displayed to the user. User select one or many checkboxes and submit, when form is submitted data are updated in database. On that moment I'm from code calling location.relaod(); In order to reload page and display correct data. </p>
  
  <p>Here is code from backend web api:</p>
  
  <pre><code>[HttpGet]
  public async Task&lt;object&gt; Get()
  {
      var entries = await _entryRepository.GetEntriesByUserIdAsync(await GetUserId());
  
      var result = _mapper.Map&lt;IEnumerable&lt;Entries&gt;, IEnumerable&lt;EntryReponse&gt;&gt;(entries);
  
      return Ok(result);
  }
  </code></pre>
  
  <p>Here is code of service which is calling web api:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Http, Headers, RequestOptions } from '@angular/http';
  import 'rxjs/add/operator/map';
  import { AuthService } from "./auth.service";
  import { Entry } from "../models/entry";
  import { Observable } from 'rxjs/Rx';
  
  @Injectable()
  export class EntryService
  {
      private readonly API_URL = 'http://localhost:52841/api/entry/';
      constructor(private http: Http,
          private authService: AuthService) { }
  
  
      createEntry(id) {
          let headers = new Headers();
          headers.append('Authorization', "Bearer " + this.authService.token);
  
          let options = new RequestOptions({ headers: headers });
  
          return this.http.post(this.API_URL + id, null,options);
      }
  
      get() {
          let headers = new Headers();
          headers.append('Authorization', "Bearer " + this.authService.token);
  
          let options = new RequestOptions({ headers: headers });
          return this.http.get(this.API_URL,  options).map(res =&gt; res.json());
      }
  
      update(entry: Entry){
  
          let headers = new Headers();
          headers.append('Authorization', "Bearer " + this.authService.token);
  
          let options = new RequestOptions({ headers: headers });
          return this.http.put(this.API_URL, entry, options);
      }
  </code></pre>
  
  <p>Here is code of component:</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { EntryService } from "../../services/entry.service";
  import { MasterCodeService } from "../../services/masterCode.service";
  import { SubCodeService } from "../../services/subcode.service";
  import { Entry } from "../../models/entry";
  import { MasterCode } from "../../models/masterCodes";
  
  
  
  @Component({
      selector: 'entry-list',
      templateUrl: './entry-list.component.html'
  })
  export class EntryListComponent implements OnInit {
  
  
  
      private readonly PAGE_SIZE = 100;
  
  
      query: any = {
          pageSize: this.PAGE_SIZE
      };
      masterCodes: any = [];
      subCodes: any = [];
      masterCode: MasterCode = new MasterCode();
      entries: Entry[];
      entry: Entry ={
          id: [],
          masterCodeId: 0,
          subCodeId: 0,
          accepted: 0,
          rejected:0
  };
  
  
  columns = [
          { title: "#" },
          { title: "PO" },
          { title: "SKU" },
          { title: "Status" }
      ];
      constructor(private entryService: EntryService,
          private masterCodeService: MasterCodeService,
          private subCodeService: SubCodeService) {
  
      }
  
      load() {
          this.masterCodeService.getMasterCodes(this.query).subscribe(res =&gt; {
              this.masterCodes = res;
          });
          this.entryService.get().subscribe(res =&gt; {
              this.entries = res;
  
          });
  
      }
  
      ngOnInit() {
          this.load();
  
  
      }
  
      onChange(event) {
          var selectedMasterCode = this.masterCodes.items.find(x =&gt; x.id == event.target.value);
          this.entry.masterCodeId = selectedMasterCode.id;
          this.subCodeService
              .getSubCodes()
              .subscribe(res =&gt; this.subCodes = res.filter(x=&gt;x.masterCode.id == selectedMasterCode.id));
      }
  
      submit(event) {
  
          if (event.target["noError"]) {
  
                  this.entry.accepted = 0;
                  this.entry.rejected = 0;
          }
          if (event.target["accepted"] &amp;&amp; event.target["accepted"].checked === true ) {
              this.entry.accepted = 1;
              this.entry.rejected = 0;
  
  
          }
          if (event.target["rejected"] &amp;&amp; event.target["rejected"].checked === true ) {
              this.entry.accepted = 0;
              this.entry.rejected = 1;
          }
  
  
          this.entryService.update(this.entry).subscribe(x =&gt; {
              location.reload();
              this.load();
          });
      }
  
      selectSubCode(event) {
          this.entry.subCodeId = event.target.value;
      }
  
  
      onEntryToggle(entryId, $event) {
          if ($event.target.checked)
              this.entry.id.push(entryId);
          else {
              var index = this.entry.id.indexOf(entryId);
              this.entry.id.splice(index, 1);
          }
  
      }
  
  
  
  }
  </code></pre>
  
  <p>After submit is called I'm getting next error:</p>
  
  <blockquote>
    <blockquote>
      <p>An unhandled exception occurred while processing the request. JsonReaderException: Unexpected character encountered while parsing
      value: {. Path 'errorMessage', line 1, position 17.
      Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)</p>
    </blockquote>
    
    <p>Stack Query Cookies Headers JsonReaderException: Unexpected character
    encountered while parsing value: {. Path 'errorMessage', line 1,
    position 17. Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType
    readType) Newtonsoft.Json.JsonTextReader.ReadAsString()
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader
    reader, JsonContract contract, bool hasConverter)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(object
    newObject, JsonReader reader, JsonObjectContract contract,
    JsonProperty member, string id)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader
    reader, Type objectType, JsonContract contract, JsonProperty member,
    JsonContainerContract containerContract, JsonProperty containerMember,
    object existingValue)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader
    reader, Type objectType, JsonContract contract, JsonProperty member,
    JsonContainerContract containerContract, JsonProperty containerMember,
    object existingValue)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader
    reader, Type objectType, bool checkAdditionalContent)
    Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,
    Type objectType) Newtonsoft.Json.JsonConvert.DeserializeObject(string
    value, Type type, JsonSerializerSettings settings)
    Newtonsoft.Json.JsonConvert.DeserializeObject(string value,
    JsonSerializerSettings settings)
    Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+d__7.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance+d__13.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    Microsoft.AspNetCore.NodeServices.NodeServicesImpl+d__10.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    Microsoft.AspNetCore.NodeServices.NodeServicesImpl+d__10.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper+d__29.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)
    Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner+d__0.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)
    AspNetCore._Views_Home_Index_cshtml+d__12.MoveNext() in
    Index.cshtml</p>
  </blockquote>
  
  <p>Please can you give me suggest how I can fix this ?
  P.S. Same error I'm getting also if I don't submit form just pres F5 to reload page.</p>
  
  <p><strong>Update</strong>
  Here is JSON on first call:
  <a href="https://i.stack.imgur.com/6ScMv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6ScMv.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/qyO73.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qyO73.png" alt="From Network panel"></a></p>
  
  <p>And after reloading:
  <a href="https://i.stack.imgur.com/dHMOK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dHMOK.png" alt="enter image description here"></a></p>
  
  <p>Header 1st call:
  <a href="https://i.stack.imgur.com/zZCiW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zZCiW.png" alt="enter image description here"></a></p>
  
  <p>Header after reloading:
  <a href="https://i.stack.imgur.com/mhhNX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mhhNX.png" alt="enter image description here"></a></p>
  
  <p>What I had understand for some URL paths reloading is working and for some of them is not working. To recap, some of routes can be called manually typed into browser and some of them only calling from links, why ? How I can figure where is mistake if all links, all components, all services are created on same way ?
  Kind Regards,
  Danijel</p>