0

I have madethe following code. So I have to retrieve data from json and present them in react. I have basicly one nested .joson object inside the other one. I know to to retrieve needed data from "root" json, but have a problem with doing it for other one. In this example I got as output enter image description here Now I don't need all thath json object inside, just Neko from name. I have tried {props.pred.nastavnik.name} but it did not work. (it didn't gave any output)

 <CardContent>
            <Typography className={classes.title} color="textSecondary" gutterBottom>
                Nastavnik
            </Typography>
            <Typography variant="h5" component="h2">
                {props.pred.nastavnik}
            </Typography>
            <Typography className={classes.title} color="textSecondary" gutterBottom>
                Br studenata
            </Typography>
            <Typography variant="h5" component="h2">
                {props.pred.broj_studenata}
            </Typography>



        </CardContent>

Every help would be great

1 Answer 1

1

nastavnik variable is a string. You should convert it to object by: JSON.parse(str) For example:

const str = '{"id":2,"admin":false,"name":"Neko","sifra":"sifra"}'
console.log(JSON.parse(str))

Sign up to request clarification or add additional context in comments.

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.