admin管理员组文章数量:1403461
I have an array result coming from a fetch, and when I send a console.log(json) it shows me the following array data:
[{"accuracy": 0, "address": "Parque das Nações, Parnamirim, , Rio Grande do Norte, BR", "altitude": 0, "attributes": {"batteryLevel": 100, "blocked": false, "charge": true, "distance": 0, "hours": 69440243, "ignition": false, "motion": false, "rssi": 1, "status": 4, "totalDistance": 4544404.921780741, "type": 19}, "course": 349, "deviceId": 3, "deviceTime": "2025-03-21T19:31:03.110+00:00", "fixTime": "2025-03-21T18:49:15.000+00:00", "geofenceIds": null, "id": 13647, "latitude": xxxx, "longitude": xxxxxx, "network": null, "outdated": false, "protocol": "gt06", "serverTime": "2025-03-21T19:31:03.110+00:00", "speed": 0, "valid": true}, {"accuracy": 0, "address": "Rio Grande do Norte, BR", "altitude": 0, "attributes": {"batteryLevel": 100, "blocked": false, "charge": true, "distance": 0, "hours": 290877, "ignition": false, "motion": false, "rssi": 4, "status": 69, "totalDistance": 4181458.924858348, "type": 19}, "course": 237, "deviceId": 10, "deviceTime": "2025-03-21T19:31:48.024+00:00", "fixTime": "2025-03-21T19:08:02.000+00:00", "geofenceIds": null, "id": 13648, "latitude": xxxx, "longitude": xxxx, "network": null, "outdated": false, "protocol": "gt06", "serverTime": "2025-03-21T19:31:48.024+00:00", "speed": 0, "valid": true}]
but when I send console.log(json.address) it returns undefined. What's wrong?
fetch code
async function buscarPosicoes() {
fetch(";)
.then((resposta) => resposta.json())
.then((json) => {
setPositions(json);
console.log(json);
})
.catch((error) => console.error(error));
I have an array result coming from a fetch, and when I send a console.log(json) it shows me the following array data:
[{"accuracy": 0, "address": "Parque das Nações, Parnamirim, , Rio Grande do Norte, BR", "altitude": 0, "attributes": {"batteryLevel": 100, "blocked": false, "charge": true, "distance": 0, "hours": 69440243, "ignition": false, "motion": false, "rssi": 1, "status": 4, "totalDistance": 4544404.921780741, "type": 19}, "course": 349, "deviceId": 3, "deviceTime": "2025-03-21T19:31:03.110+00:00", "fixTime": "2025-03-21T18:49:15.000+00:00", "geofenceIds": null, "id": 13647, "latitude": xxxx, "longitude": xxxxxx, "network": null, "outdated": false, "protocol": "gt06", "serverTime": "2025-03-21T19:31:03.110+00:00", "speed": 0, "valid": true}, {"accuracy": 0, "address": "Rio Grande do Norte, BR", "altitude": 0, "attributes": {"batteryLevel": 100, "blocked": false, "charge": true, "distance": 0, "hours": 290877, "ignition": false, "motion": false, "rssi": 4, "status": 69, "totalDistance": 4181458.924858348, "type": 19}, "course": 237, "deviceId": 10, "deviceTime": "2025-03-21T19:31:48.024+00:00", "fixTime": "2025-03-21T19:08:02.000+00:00", "geofenceIds": null, "id": 13648, "latitude": xxxx, "longitude": xxxx, "network": null, "outdated": false, "protocol": "gt06", "serverTime": "2025-03-21T19:31:48.024+00:00", "speed": 0, "valid": true}]
but when I send console.log(json.address) it returns undefined. What's wrong?
fetch code
async function buscarPosicoes() {
fetch("https://xxx.xxx")
.then((resposta) => resposta.json())
.then((json) => {
setPositions(json);
console.log(json);
})
.catch((error) => console.error(error));
Share
Improve this question
asked Mar 21 at 19:44
Junior SilvaJunior Silva
132 bronze badges
1
- 1 your array doesn't have an address property... items within the array do. – Kevin B Commented Mar 21 at 19:50
1 Answer
Reset to default 0try with:
console.log(json[0].address);
本文标签: consolelog does not return json attribute valueonly arrayReact NativeStack Overflow
版权声明:本文标题:console.log does not return json attribute value, only array - React Native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744336175a2601202.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论