我确实得到了一个google costumsearch,有200个ok,但我没有在我的应用程序中正确地获得信息,我的代码看起来像这样,我想要得到项目,但它返回未被罚款
fetch(
"https://www.googleapis.com/customsearch/v1?key={key}&cx={cx}&q=" +
this.state.query
).then(response => {
this.setState({ results: response.items });
console.log(response.items);
});发布于 2019-07-07 12:25:53
方法fetch不返回响应体,它返回一个响应对象。要将响应体作为json获得,可以使用json方法,它返回一个新的承诺,该承诺的解析结果是将正文文本解析为JSON:
fetch("https://www.googleapis.com/customsearch/v1?key={key}&cx={cx}&q=" + this.state.query)
.then(response => response.json())
.then(response => {
this.setState({ results: response.items });
console.log(response.items);
});发布于 2019-07-07 12:24:00
做response.json().then(() => {})
https://stackoverflow.com/questions/56922098
复制相似问题