Note that there are some explanatory texts on larger screens.

plurals
  1. POcheck to see if a sub array exists in JSON
    primarykey
    data
    text
    <p>Here is the json Sample:</p> <pre><code> { "kind": "shopping#product", "id": "tag:google.com,2010:shopping/products/6582229/17914968800165668776", "selfLink": "https://www.googleapis.com/shopping/search/v1/public/products/6582229/gid/17914968800165668776?alt\u003djson", "product": { "googleId": "17914968800165668776", "author": { "name": "Red Tag Market", "accountId": "6582229" }, "creationTime": "2010-11-30T10:00:00.000Z", "modificationTime": "2011-05-01T09:20:00.000Z", "country": "US", "language": "en", "title": "The Fantastic Mr. Fox - BLU-RAY/DVD", "description": "Wit.", "link": "ht361", "condition": "new", "gtin": "00024543657552", "inventories": [ { "channel": "online", "price": 22.51, "currency": "USD" } ], "images": [ { "link": "http://208.131.143.232/i/6/3/0/7/6/1/8.jpg", "thumbnails": [ { "width": 60, "height": 60, "link": "hBEevU46OsArJElwIeErF_3E7Zzu12M2eLSvQBdYiMLaRWrI60aF8lHxRqOz-wkx2YJUIVdCrzrEQDWxgcc" } ] } ] } }, { "kind": "shopping#product", "id": "tag:google.com,2010:shopping/products/6296724/17894083551590155418", "selfLink": "https://www.googleapis.com/shopping/search/v1/public/products/6296724/gid/17894083551590155418?alt\u003djson", "product": { "googleId": "17894083551590155418", "author": { "name": "eBay", "accountId": "6296724" }, "creationTime": "2011-04-04T00:43:02.000Z", "modificationTime": "2011-04-04T00:43:02.000Z", "country": "US", "language": "en", "title": "Fy.", "link": "htt530831212&amp;itemid\u003d140530831212&amp;icep_meta_categ_id\u003d11232", "condition": "used", "gtin": "00024543657552", "inventories": [ { "channel": "online", "price": 14.99, "currency": "USD" } ], "images": [ { "link": "http://i.ebayimg.com/00/%24%28KGrHqYOKkQE1r4Vh1gFBNl4n0t17g%7E%7E_1.JPG?set_id\u003d8800005007", "thumbnails": [ { "width": 60, "height": 60, "link": "http://lh } ] } ] } } </code></pre> <p>What I want to do is see if <code>data.items[i].product.images[]</code> exists or not. as you can see the Images array does not present in the second response thus killing my javascript at the point I try to use <code>data.items[i].product.images[]</code> for any purpose. I have been looking and have yet to find a solution.</p> <p>Edit: I just tried this and still no dice:</p> <pre><code>if(data.items[i].product.images !== undefined){ var image = 'images/inverticon.png'; }else{ var image = data.items[i].product.images[0].thumbnails[0].link; } </code></pre> <p>I do not get any errors, the script just stops running. If I omit the image code everything works fine and as long as the returned JSON has the image[] it works fine.</p> <p>Edit: here is the solution:</p> <pre><code>if(data.items[i].product.images !== undefined){ var image = data.items[i].product.images[0].thumbnails[0].link; }else{ var image = 'images/inverticon.png'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload