how to map one nested json data in react js example i want to display the product images that i recived from api
export class Planview extends Component{
constructor() {
super();
this.state = {
package: [],
};
}
componentDidMount() {
const ProdID = this.props.match.params.ProductID
fetch(`http://127.0.0.1:8000/api/plan/${ProdID}/`)
.then(response => response.json())
.then(responseData => {
this.setState({
package: responseData
});
})
.catch(error => {
console.log('Error fetching and parsing data', error);
});
}
render(){
return(<>
<div className="container mar" >
<h1 className="my-4">{this.state.package.title}</h1>
<div className="row">
<div className="col-md-offset-2">
<div className="row" id="gradient">
<div className="col-md-6 img-responsive">
<img
className ="img-main img"
src={"http://127.0.0.1:8000"+this.state.package.thumbnail}
alt="main"
fluid ="True"/>
</div>
<div className="col-md-6" id="overview">
<h4>{this.state.package.code}</h4>
<h5><small> {this.state.package.created_at}</small></h5
</div>
<div className="row mt-4">
<h3><small></small></h3>
<div className="row">
{
this.state.package.image.map(function (person, index) {
return (
<div className="col" key={index}>
<img className={person.image} src="" alt="1"/>
</div>
)})}
</div>
</div>
</div>
<div className="row">
<h3 className="my-4">{this.state.package.description}</h3>
</div>
</div>
</div>
</div>
</> );
}
}
export default Planview;
and my json is like
`{id: 1, image: [{image: "/media/plan_images/Home-5-E-plan-1024x684.jpg"},…],
title: "sample",…}`
expand of json like
`code: "MAG0001"
created_at: "2020-11-23"
description: "college book"
details: {age: 31, city: "New York", name: "John"}
id: 1
image: [{image: "/media/plan_images/Home-5-E-plan-1024x684.jpg"},
{image: "/media/plan_images/Home-4-E-plan-1024x684.jpg"},
{image: "/media/plan_images/Home-3-E-plan-1024x684.jpg"},
]
slug: "sample"
thumbnail: "/media/plan_images/900-square-feet-home-plan.jpg"
title: "sample"`
from the above json i want to display the image from the field image array it contains multiple images and also the json data in the field name details
<img src={person.image} alt="1"/>- Check the image path is correctpackageshould beobjectinstead of array. this.state = { package:{ image: []}, };this.state.package.image && this.state.package.image.map