I'm trying to get values from JSON that looks like this:
{
"id": 371,
"city": "London",
"name": "London Station",
"trains": [
{
"id": 375,
"number": "1023",
"numberOfCarriages": "21"
}
]
}
I want to get values from trains, like number and numberOfCarriages. I'm trying to get those values in React. My React code:
class ViewTrainsComponent extends Component {
constructor(props) {
super(props)
this.state = {
id: this.props.match.params.id,
station: []
}
}
render() {
return (
<div>
<div className="row">
{/* <div>{this.state.station[0].trains[0].number}</div> */}
</div>
</div>
);
}
}
Am I doing it right? How can I get those values in render function?
EDIT.
Here is the response from API
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…