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
Add a comment  | 

1 Answer 1

Reset to default 0

try with:

console.log(json[0].address);

本文标签: consolelog does not return json attribute valueonly arrayReact NativeStack Overflow