JSON.parse(<anonymous>)位置0的JSON中出现意外的标记P

时间:2018-04-19 14:38:42

标签: angular typescript download

我想下载file.docx表格ws。我在邮递员send and download中使用,我的file.docx也没问题。

为此,我尝试了这段代码。

 public download(id: string): Observable<Sale[]> {
    let headers = new Headers();
    headers.append('x-access-token', this.auth.getCurrentUser().token);
    headers.append('id', id);
    return this.http.get(Api.getUrl(Api.URLS.download), {
      headers: headers
    })
      .map((response: Response) => {
        let res = response.json();
        console.log(res)    //Unexpected token P in JSON at position 0     at JSON.parse (<anonymous>)
        if (res.StatusCode === 0) {
          this.auth.logout();
        } else {
          return res.StatusDescription.map(sale => {
            return new Sale(sale);
          });
        }
      });
  }

Ts代码:

  download(id: string) {
    this.ss.download(id).subscribe(
      saledownload => {
        console.log(saledownload)
        this.saledownload = saledownload;
      }
    );
  }

0 个答案:

没有答案