Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xml文件加载显示json错误_Xml_Angular_Http Headers_Angular5_Angular Httpclient - Fatal编程技术网

xml文件加载显示json错误

xml文件加载显示json错误,xml,angular,http-headers,angular5,angular-httpclient,Xml,Angular,Http Headers,Angular5,Angular Httpclient,在我的应用程序中,我试图加载XML文件以使用他的数据。 但我在Chrome浏览器控制台中遇到了一个错误: {错误:SyntaxError:JSON中的意外标记{console.log(response);});尝试一下,告诉我你看到了什么 import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable }

在我的应用程序中,我试图加载
XML
文件以使用他的数据。 但我在Chrome浏览器控制台中遇到了一个错误:

{错误:SyntaxError:JSON中的意外标记<位于XMLHttp的JSON.parse()处的位置0处

服务台 但这似乎是:

还尝试使用

Content type是一种指定从客户端发送到服务器的请求的媒体类型的方法,以及
HttpClient.get()
默认情况下,如果您请求的是非JSON数据,则返回JSON,您需要使用
responseType:'text'
选项,如我在其中一个链接中所述shared@Vikas,我已经偶然发现了这些,但它们对我不起作用。请看问题,我在问题底部添加了
this.\u http.get(this.\u url,{responseType:'text'}).subscribe(response=>{console.log(response);});
尝试一下,告诉我你看到了什么
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class ReadDataService {
  headers = new HttpHeaders({ 'Content-Type': 'text/xml' });
  xml: string;
  private _url: string = "../../assets/sf9_commandpacket.xml";

 constructor(private _http:HttpClient) {}

  getData(): Observable<string> {
  return this._http.get<string>(this._url, { headers: this.headers });
  }
 }
}
this._http.get(this._url, { headers: this.headers, responseType: text / xml }).subscribe(response => { return response; })