transSpecialChar是对字符串处理的函数 interface Body {readonly body: Re
使用fetch进行数据请求返回response东西,response.json报错。原因是response中含有特殊字符。
fetch(url).then(response => response.json()) .then(data => console.log(data)) .catch(e => console.log("Oops, error", e))
打消response.json()挪用,使用response.text()返回请求数据的字符串,对特殊字符进行转义替换措置惩罚惩罚后,再进行json东西化传入请求告成的回调函数中。transSpecialChar是对字符串措置惩罚惩罚的函数
interface Body {
readonly body: ReadableStream<Uint8Array> | null;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
json(): Promise<any>;
text(): Promise<string>;
}
response.text().then((text) => { const json = JSON.parse(this.transSpecialChar(text)); successCallBack(json); }
使用fetch进行数据请求时报json错误
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32003.html