0

There is the remote array that I have to fetch in React Native. I can return "name" in the array but I can't return url in the array in an array. This is my array.

{
  "data": [
    {
      "id": 1,
      "attributes": {
        "name": "Apple",
        "media": {
          "data": [
            {
              "id": 12,
              "attributes": {
                "url": "https://example.com/1.jpg"
              }
            }
          ]
        }
      }
    },
    {
      "id": 2,
      "attributes": {
        "name": "Banana",
        "media": {
          "data": [
            {
              "id": 11,
              "attributes": {
                "url": "https://example.com/2.jpg"
              }
            }
          ]
        }
      }
    }
  ],
}

This is my React Native code.

<Text>{`${item.attributes.name}`}</Text>
<Image
  source={{ uri: item.attributes.media.??? }}
  style={styles.image}
/>
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Hong
  • 3
  • 1
  • Does this answer your question? [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – Heretic Monkey Jun 17 '22 at 17:08
  • `item.attributes.media.data[0].attributes.url`, as long as data[] has an element at index 0. – Matthew M. Jun 17 '22 at 17:42

0 Answers0