Home > Mobile >  Display objects from json file
Display objects from json file

Time:10-11

Please show me how to map and access the data. I need to print out a list of all "url" This is how the json looks like

  return pressReleases ? (
<Main>
  {pressReleases.map((item) => (
    <TextCell key={item.news_id}>
      <CategoryText>
        {item.content.attachments.url}
      </CategoryText>
    </TextCell>
  ))}
  ;
</Main>

) : null; };

CodePudding user response:

Attachment is an array of objects and each object has the key call url which is what you want to retrieve and print it out. In order to do that you need to iterate over the attachments array.

...
...
<CategoryText>
   {item.content.attachments.map(attachment => (
      <p>{attachment.url}</p>
   )}
</CategoryText>
...
...
  • Related