Iterating over JSON received data


#1

This is the pic of console.log for the received json.


Can anyone please tell how to iterate over this i am not able to iterate.

currently i am using this code to iterate but this is not working.

home.html

<div *ngFor="let item of allItems">
    <p> {{item.Item.ASIN}} </p>
  </div>

home.ts

 public allItems:any[]=[];
  public test:any;

  constructor(public navCtrl: NavController, public http:Http ,public navParams: NavParams) {
    this.http.get('http://localhost/bar/dev/item_search.php?keyword=new')
                .subscribe(res => {this.allItems = res.json(); console.log(this.allItems);         
        });
  }

Thanks in advance…


#2

Please post the result of JSON.stringify(this.allItems) (as text, not as an image).


#3

the response is too big…but still if you ask

[{“Request”:{“IsValid”:“True”,“ItemSearchRequest”:{“Keywords”:“j7”,“ResponseGroup”:[“Images”,“ItemAttributes”,“Offers”],“SearchIndex”:“Electronics”,“Sort”:“relevancerank”}},“TotalResults”:“1096185”,“TotalPages”:“109619”,“MoreSearchResultsUrl”:“https://www.amazon.in/gp/search?linkCode=xm2&SubscriptionId=AKIAJDFOBDG56PTMTDDQ&keywords=j7&tag=rohananand-21&creative=165953&url=search-alias%3Delectronics&camp=2025",“Item”:[{“ASIN”:“B014DYVWWS”,“ParentASIN”:“B01LD4KP42”,“DetailPageURL”:“https://www.amazon.in/Samsung-SMG_SM-J700F_GOD-Galaxy-J7-Gold/dp/B014DYVWWS?psc=1&SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B014DYVWWS”,“ItemLinks”:{“ItemLink”:[{“Description”:"Add To Wishlist”,“URL”:“https://www.amazon.in/gp/registry/wishlist/add-item.html?asin.0=B014DYVWWS&SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B014DYVWWS"},{“Description”:"Tell A Friend”,“URL”:“https://www.amazon.in/gp/pdp/taf/B014DYVWWS?SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B014DYVWWS"},{“Description”:"All Customer Reviews”,“URL”:“https://www.amazon.in/review/product/B014DYVWWS?SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B014DYVWWS"},{“Description”:"All Offers”,“URL”:“https://www.amazon.in/gp/offer-listing/B014DYVWWS?SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B014DYVWWS"}]},“SmallImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL75.jpg”,“Height”:“75”,“Width”:“41”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL160.jpg”,“Height”:“160”,“Width”:“87”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.jpg",“Height”:“500”,“Width”:“272”},“ImageSets”:{“ImageSet”:[{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/31Y%2BoIOzeuL.SL30.jpg”,“Height”:“30”,“Width”:“16”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31Y%2BoIOzeuL.SL75.jpg”,“Height”:“75”,“Width”:“40”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31Y%2BoIOzeuL.SL75.jpg”,“Height”:“75”,“Width”:“40”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31Y%2BoIOzeuL.SL110.jpg”,“Height”:“110”,“Width”:“59”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31Y%2BoIOzeuL.SL160.jpg”,“Height”:“160”,“Width”:“86”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31Y%2BoIOzeuL.jpg",“Height”:“500”,“Width”:“269”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/21cfdCg9%2BoL.SL30.jpg”,“Height”:“30”,“Width”:“3”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21cfdCg9%2BoL.SL75.jpg”,“Height”:“75”,“Width”:“9”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21cfdCg9%2BoL.SL75.jpg”,“Height”:“75”,“Width”:“9”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21cfdCg9%2BoL.SL110.jpg”,“Height”:“110”,“Width”:“13”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21cfdCg9%2BoL.SL160.jpg”,“Height”:“160”,“Width”:“18”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21cfdCg9%2BoL.jpg",“Height”:“500”,“Width”:“57”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/21q%2BeN8LK5L.SL30.jpg”,“Height”:“30”,“Width”:“4”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21q%2BeN8LK5L.SL75.jpg”,“Height”:“75”,“Width”:“9”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21q%2BeN8LK5L.SL75.jpg”,“Height”:“75”,“Width”:“9”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21q%2BeN8LK5L.SL110.jpg”,“Height”:“110”,“Width”:“13”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21q%2BeN8LK5L.SL160.jpg”,“Height”:“160”,“Width”:“20”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/21q%2BeN8LK5L.jpg",“Height”:“500”,“Width”:“61”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/41r6%2BZDG8lL.SL30.jpg”,“Height”:“30”,“Width”:“13”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41r6%2BZDG8lL.SL75.jpg”,“Height”:“75”,“Width”:“32”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41r6%2BZDG8lL.SL75.jpg”,“Height”:“75”,“Width”:“32”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41r6%2BZDG8lL.SL110.jpg”,“Height”:“110”,“Width”:“47”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41r6%2BZDG8lL.SL160.jpg”,“Height”:“160”,“Width”:“69”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41r6%2BZDG8lL.jpg",“Height”:“500”,“Width”:“215”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/31oIvKcpLoL.SL30.jpg”,“Height”:“30”,“Width”:“9”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31oIvKcpLoL.SL75.jpg”,“Height”:“75”,“Width”:“24”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31oIvKcpLoL.SL75.jpg”,“Height”:“75”,“Width”:“24”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31oIvKcpLoL.SL110.jpg”,“Height”:“110”,“Width”:“35”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31oIvKcpLoL.SL160.jpg”,“Height”:“160”,“Width”:“50”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31oIvKcpLoL.jpg",“Height”:“500”,“Width”:“157”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/41iTH9Ak4AL.SL30.jpg”,“Height”:“30”,“Width”:“13”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41iTH9Ak4AL.SL75.jpg”,“Height”:“75”,“Width”:“32”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41iTH9Ak4AL.SL75.jpg”,“Height”:“75”,“Width”:“32”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41iTH9Ak4AL.SL110.jpg”,“Height”:“110”,“Width”:“46”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41iTH9Ak4AL.SL160.jpg”,“Height”:“160”,“Width”:“68”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41iTH9Ak4AL.jpg",“Height”:“500”,“Width”:“211”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/31ZNqU%2Bsy1L.SL30.jpg”,“Height”:“30”,“Width”:“9”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31ZNqU%2Bsy1L.SL75.jpg”,“Height”:“75”,“Width”:“23”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31ZNqU%2Bsy1L.SL75.jpg”,“Height”:“75”,“Width”:“23”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31ZNqU%2Bsy1L.SL110.jpg”,“Height”:“110”,“Width”:“34”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31ZNqU%2Bsy1L.SL160.jpg”,“Height”:“160”,“Width”:“49”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/31ZNqU%2Bsy1L.jpg",“Height”:“500”,“Width”:“154”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/41gnU0YPKDL.SL30.jpg”,“Height”:“18”,“Width”:“30”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41gnU0YPKDL.SL75.jpg”,“Height”:“45”,“Width”:“75”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41gnU0YPKDL.SL75.jpg”,“Height”:“45”,“Width”:“75”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41gnU0YPKDL.SL110.jpg”,“Height”:“67”,“Width”:“110”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41gnU0YPKDL.SL160.jpg”,“Height”:“97”,“Width”:“160”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41gnU0YPKDL.jpg",“Height”:“303”,“Width”:“500”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/414PriitmOL.SL30.jpg”,“Height”:“18”,“Width”:“30”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/414PriitmOL.SL75.jpg”,“Height”:“46”,“Width”:“75”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/414PriitmOL.SL75.jpg”,“Height”:“46”,“Width”:“75”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/414PriitmOL.SL110.jpg”,“Height”:“68”,“Width”:“110”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/414PriitmOL.SL160.jpg”,“Height”:“98”,“Width”:“160”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/414PriitmOL.jpg",“Height”:“307”,“Width”:“500”}},{"@attributes":{“Category”:“variant”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/41hAxxIpnvL.SL30.jpg”,“Height”:“22”,“Width”:“30”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41hAxxIpnvL.SL75.jpg”,“Height”:“56”,“Width”:“75”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41hAxxIpnvL.SL75.jpg”,“Height”:“56”,“Width”:“75”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41hAxxIpnvL.SL110.jpg”,“Height”:“82”,“Width”:“110”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41hAxxIpnvL.SL160.jpg”,“Height”:“120”,“Width”:“160”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41hAxxIpnvL.jpg",“Height”:“375”,“Width”:“500”}},{"@attributes":{“Category”:“primary”},“SwatchImage”:{“URL”:"https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL30.jpg”,“Height”:“30”,“Width”:“16”},“SmallImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL75.jpg”,“Height”:“75”,“Width”:“41”},“ThumbnailImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL75.jpg”,“Height”:“75”,“Width”:“41”},“TinyImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL110.jpg”,“Height”:“110”,“Width”:“60”},“MediumImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.SL160.jpg”,“Height”:“160”,“Width”:“87”},“LargeImage”:{“URL”:“https://images-eu.ssl-images-amazon.com/images/I/41VT5dAm7DL.jpg",“Height”:“500”,“Width”:“272”}}]},“ItemAttributes”:{“Binding”:"Wireless Phone Accessory”,“Brand”:“Samsung”,“Color”:“Gold”,“EAN”:“8806086845892”,“EANList”:{“EANListElement”:“8806086845892”},“Feature”:[“13MP primary camera with auto focus, LED flash, geotagging, touch focus, face detection, panorama and 5MP front facing camera”,“5.5-inch (13.97 centimeters) Super AMOLED capacitive touchscreen with 720 x 1280 pixels resolution, 267 ppi pixel density and 16M color support”,“Android v5.1 Lollipop operating system with 1.5GHz octa core processor, Mali T720MP2 GPU, 1.5GB RAM, 16GB internal memory expandable up to 128GB and dual micro SIM (4G+4G)”,“3000mAH lithium-ion battery”,“1 year manufacturer warranty for device and 6 months manufacturer warranty for in-box accessories including batteries from the date of purchase”],“ItemDimensions”:{“Height”:“598”,“Length”:“311”,“Weight”:“38”,“Width”:“31”},“Label”:“Samsung”,“LegalDisclaimer”:“1 year manufacturer warranty for device and 6 months manufacturer warranty for in-box accessories including batteries from the date of purchase”,“ListPrice”:{“Amount”:“1095000”,“CurrencyCode”:“INR”,“FormattedPrice”:“INR 10,950.00”},“Manufacturer”:“Samsung”,“Model”:“SMG_SM-J700F_GOD”,“MPN”:“SMG_SM-J700F_GOD”,“OperatingSystem”:“Android”,“PackageDimensions”:{“Height”:“197”,“Length”:“638”,“Weight”:“75”,“Width”:“346”},“PackageQuantity”:“1”,“PartNumber”:“SMG_SM-J700F_GOD”,“ProductGroup”:“Wireless”,“ProductTypeName”:“WIRELESS_ACCESSORY”,“Publisher”:“Samsung”,“Studio”:“Samsung”,“Title”:“Samsung Galaxy J7 (Gold)”,“Warranty”:“1 year manufacturer warranty for device and 6 months manufacturer warranty for in-box accessories including batteries from the date of purchase”},“OfferSummary”:{“LowestNewPrice”:{“Amount”:“1095000”,“CurrencyCode”:“INR”,“FormattedPrice”:“INR 10,950.00”},“TotalNew”:“34”,“TotalUsed”:“0”,“TotalCollectible”:“0”,“TotalRefurbished”:“0”},“Offers”:{“TotalOffers”:“1”,“TotalOfferPages”:“1”,“MoreOffersUrl”:“https://www.amazon.in/gp/offer-listing/B014DYVWWS?SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B014DYVWWS",“Offer”:{“OfferAttributes”:{“Condition”:“New”},“OfferListing”:{“OfferListingId”:“dyslMHTYr7FpUdZBX%2FxEQBhK0ytVBK7xTM0UTHIUEB6ednzZfXhQK00h5XVYKZe8J9OfXYqTDvNXU7oC9cLjagSJurFIsijXDitvJLLqhSRrX0mggUjgpZzijpAAK57NAgCQetQJ9fIquKqaWaSc6Q%3D%3D”,“Price”:{“Amount”:“1095000”,“CurrencyCode”:“INR”,“FormattedPrice”:"INR 10,950.00”},“Availability”:“Usually dispatched within 24 hours”,“AvailabilityAttributes”:{“AvailabilityType”:“now”,“MinimumHours”:“0”,“MaximumHours”:“0”},“IsEligibleForSuperSaverShipping”:“1”,“IsEligibleForPrime”:“1”}}}},{“ASIN”:“B01LY4V6IM”,“ParentASIN”:“B01N0NT004”,“DetailPageURL”:“https://www.amazon.in/Samsung-Galaxy-Prime-SM-G610F-Gold/dp/B01LY4V6IM?psc=1&SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B01LY4V6IM",“ItemLinks”:{“ItemLink”:[{“Description”:"Add To Wishlist”,“URL”:“https://www.amazon.in/gp/registry/wishlist/add-item.html?asin.0=B01LY4V6IM&SubscriptionId=AKIAJDFOBDG56PTMTDDQ&tag=rohananand-21&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B01LY4V6IM"},{“Description”:"Tell A Friend”,“URL”:"https://www.amazon.in/gp/pdp/taf/B01LY4V6IM?

this is just some part of it…


#4

Sorry, but I need the whole thing or else it’s not properly formatted JSON and I can’t use my IDE to format it. Use pastebin or something if you wish.


#5

This is the paste bin url
https://pastebin.com/QkmR8Ycf


#6

Sorry just edited it…a bit thing changed in the data received


#7

Got it.

<div *ngFor="let item of allItems.Item">
<p>{{item.ASIN}}</p>
</div>

#8

Still not working…
can you suggest anything else


#9

Works for me. I copied that entire pastebin into this.allItems, used that template, and got the following:

B014DYVWWS
B01LY4V6IM
B06Y3JH7TN
B06Y3HFZBQ
B01618MY62
B01J14O7ZY
B01LZ4XMEX
B01DDP7D6W
B0161959NQ
B06XYL2NHB

#10

can you paste your .ts code here…


#11
allItems = {/*your entire pastebin*/};

#12

Naturally, if you’re getting this from a future, you need to seed allItems initially with something so the ngFor doesn’t choke, like:

allItems = {Item: []};

#13

Just changed allItems:any[]=[]; to allitems:any={};

All thanks to you…Thanks a lot…
You are always a great help :slight_smile:


#14

Please take the time to define proper interfaces instead of using any. It really is worth the effort. Your code will be much more readable and you will protect against typos.