0

I want to list the json response. How do i render nested json inside my jsx? following is json response

[{
    "data": {
        "total_students": 13,
        "seats": "",
        "categories": [{
            "id": 28,
            "name": "Economy",
            "slug": "economy",
        }],
        "instructor": {
            "id": "24",
            "name": "Ad",
            "sub": ""
        },
        "menu_order": 0
    },
    "headers": [],
    "status": 200
}

This is how the response looks like. Also rendering in react is as shown below

return this.state.user.map(user =>

        <CardSection>
        <View style={styles.thumbnailContainerStyle}>
        <Text key= {user.data.name} style={styles.userStyle}>{this.state.user.data}</Text>
        </View>
        </CardSection>

I have tried like the above but getting error in rendering part cannot define name of undefined.What wrong am i doing?please help

2 Answers 2

2

You don't have a key name in data object that undefined If you want to nested JSON you can access like

  • name in instructor : user.data.instructor.name
  • name in categories (array) : user.data.categories.map(category => category.name)
Sign up to request clarification or add additional context in comments.

Comments

1

user.data.name does not seem to be present in your JSON response. The name could be user.data.instructor.name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.