I have a JSON returned object from a file ./jsonData.json.
Inside this file, I have this data:
Note: This is the whole JSON data loaded from the file.
import QuizData from './quizData.json'
This is a new app, so QuizData is all of the following:
[
{
"id": 1,
"name": "Lesson 1",
"topics": [
{
"topicID": 1,
"topicName": "Science",
"topicDescription": "Science quiz questions"
},
{
"topicID": 2,
"topicName": "General Knowledge",
"topicDescription": "General Knowledge Quiz Questions"
}
]
}
]
I am trying to get the topic name for each one found and put it out as a Text.
Here is my code:
<FlatList
data={QuizData}
renderItem={({ item, index }) =>
<View>
<Text>{item.topics.topicName}</Text>
</View>
}
keyExtractor={(item) => item.topicID.toString()}
/>
I have also tried:
{item.topics.[index].topicName}
and
{item.topics[index][topicName]}
But I get the error:
undefined is not an object.
I then thought perhaps its needs to be:
data={QuizData.topics}
and then change the renderItem to:
{item.topicName}
This time there is no error, but there is also no output of text to the screen.
QuizDatais the whole json file. and that JSON shown is the whole of the json. Its a new app - im just starting out. At the top of this component I haveimport QuizData from './quizData.json'topicNameandtopicDescription.