我从json文件中接收到奇怪的字符,所以我猜编码方面存在问题,因此我需要向该服务中的http获取请求添加标头 我认为是这样
headers.append('Content-type','application / json; charset = UTF-8');
这是我的源服务代码:
import { Component, Input } from '@angular/core';
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from
'@angular/http';
import { HttpClient } from '@angular/common/http';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class listsService{
constructor(private http: HttpClient) { }
//get data from json file
getList(){
return this.http.get('../data.json')
.catch(err => {return "no data";});
}
}