【发布时间】:2019-12-17 22:31:43
【问题描述】:
我正在尝试通过 json url 复制 types[]。
我的网址打开这个:
{
"html_attributions": [],
"results": [
{
"geometry": {
"location": {
"lat": -27.00170259999999,
"lng": -48.62017489999999
},
"viewport": {
"northeast": {
"lat": -27.00031801970849,
"lng": -48.6187919197085
},
"southwest": {
"lat": -27.0030159802915,
"lng": -48.6214898802915
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id": "96213cc395d0c8ccaa3176875ec8aa2b89f852f8",
"name": "Dois Amores Comida Árabe",
"place_id": "ChIJ_RggImq22JQRqQgcG98nfn4",
"plus_code": {
"compound_code": "X9XH+8W Balneário Camboriú, SC, Brasil",
"global_code": "584HX9XH+8W"
},
"reference": "ChIJ_RggImq22JQRqQgcG98nfn4",
"scope": "GOOGLE",
=---> "types": [
"restaurant",
"food",
"point_of_interest",
"establishment"
],
"vicinity": "Avenida Atlântica, 4054 - Centro, Balneário Camboriú"
}
],
"status": "OK"
}
我想将 types [] 列表返回到列表,以便我知道该位置适合什么类型。 我没有找到任何方法,我得到了更接近的东西。
和我的代码:
const url = 'myurlgoogleapi';
fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"html_attributions": [],
"results": [{
"types" ["name"]
}]
}),
}).then((response) => response.json())
.then((responseJson) => {
console.log(responseJson[0].name);
})
.catch((error) => {
console.error(error);
});
我使用 console.log 只是为了检查是否可以工作,但只是错误。 我需要具体的 type[] 来返回你的值。
【问题讨论】:
-
错误是什么? console.log(responseJson) 给出了什么?
-
调试所有 json 正文,但不是 types[] 特定的
标签: javascript json react-native url