使用fetch进行数据请求时报json错误

使用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);
}

相关文章

最后的控制台返回空数组.控制台在ids.map函数完成之前运行va...
我正在尝试将rxJava与我已经知道的内容联系起来,特别是来自J...
config.jsconstconfig={base_url_api:"https://douban....
我正在阅读MDN中的javascript,并且遇到了这个谈论承诺并且不...
config.jsconstconfig={base_url_api:"https://douban....
这是我的代码main.cpp:#include<string>#include<...