I am unable to get data form API. I tried different way, but no luck. Here is my Code and API. I want to use these data (JSON) through react fetch method.
// My Fetch API
fetchData() {
fetch('MYAPI_URL')
.then(response => response.json())
// .then(parsedJSON => console.log(parsedJSON)) //prints the data on console
// .then(parsedJSON => console.log(parsedJSON.status)) // Not Worked
// .then(parsedJSON => console.log(parsedJSON.data.Products) ) // Not Worked
.then(parsedJSON => console.log(parsedJSON.status.data) ) // not working.
.then(parsedJSON => parsedJSON.data.map(pro => (
{
..... Other code ....
}
))
}
// below is my api data
"status": true,
"data": {
"banner": "mydomain.com/img/img1.png",
"Products": [
{
"CategoryCode": "03",
"CategoryName": "Appetizers",
"SubCategory": [
{
"SubCategoryCode": "038",
"SubCategoryName": "Chicken Wings",
"Image": "banner": "mydomain.com/img/img1.png",
"SubCategoryType": [
{
"TypeCode": "05",
"TypeName": "Normal",
"AdditionalPrice": "0",
"TypeSize": [
{
"SizeCode": "17",
"SizeName": "6 Pcs",
"Description": "Oven baked hot and spicy chicken wings.",
"Price": "349",
"Toppings": [
]
}
]
}
]
...............
// I want to get Products Code etc. But I can't. No idea where I am doing wrong
When I use this fetch api it was working. The data was almost same with the above one, but that was not real Rest API.