Note that there are some explanatory texts on larger screens.

plurals
  1. POFatal error: Cannot use object of type stdClass as array
    primarykey
    data
    text
    <p>I know this is probably something simple and I am beginning to understand how I need to go about this, I realize that this has something to do with OO however as i am new to OO and json im having a bit of a problem with this <a href="http://api.discogs.com/database/search?q=d&amp;page=1&amp;per_page=5" rel="nofollow">http://api.discogs.com/database/search?q=d&amp;page=1&amp;per_page=5</a> it returns 5 results with the query <code>d</code> in json format so i parse it with the php function and then attempt to lets say show the thubmnail for the first results this is my parse code: </p> <pre><code>$returnData = file_get_contents($queryURL); $discogsJSON = json_decode($returnData); </code></pre> <p>where <code>$queryURL</code> = the provided url. if i print <code>$discogsJSON</code> i get this:</p> <pre><code>&lt;pre&gt;stdClass Object ( [pagination] =&gt; stdClass Object ( [per_page] =&gt; 5 [items] =&gt; 179465 [page] =&gt; 1 [urls] =&gt; stdClass Object ( [last] =&gt; http://api.discogs.com/database/search?q=f&amp;per_page=5&amp;page=35893 [next] =&gt; http://api.discogs.com/database/search?q=f&amp;per_page=5&amp;page=2 ) [pages] =&gt; 35893 ) [results] =&gt; Array ( [0] =&gt; stdClass Object ( [style] =&gt; Array ( [0] =&gt; Free Jazz ) [thumb] =&gt; http://api.discogs.com/image/R-90-1672955-1305426452.jpeg [format] =&gt; Array ( [0] =&gt; Vinyl [1] =&gt; LP [2] =&gt; Album ) [country] =&gt; Switzerland [title] =&gt; Steve Lacy - Clinkers [uri] =&gt; /Steve-Lacy-Clinkers/master/54331 [label] =&gt; Array ( [0] =&gt; Hat Hut Records ) [catno] =&gt; F [year] =&gt; 1978 [genre] =&gt; Array ( [0] =&gt; Jazz ) [resource_url] =&gt; http://api.discogs.com/masters/54331 [type] =&gt; master [id] =&gt; 54331 ) [1] =&gt; stdClass Object ( [style] =&gt; Array ( [0] =&gt; Free Jazz ) [thumb] =&gt; http://api.discogs.com/image/R-90-1672955-1305426452.jpeg [format] =&gt; Array ( [0] =&gt; Vinyl [1] =&gt; LP [2] =&gt; Album ) [country] =&gt; Switzerland [title] =&gt; Steve Lacy - Clinkers [uri] =&gt; /Steve-Lacy-Clinkers/release/1672955 [label] =&gt; Array ( [0] =&gt; Hat Hut Records ) [catno] =&gt; F [year] =&gt; 1978 [genre] =&gt; Array ( [0] =&gt; Jazz ) [resource_url] =&gt; http://api.discogs.com/releases/1672955 [type] =&gt; release [id] =&gt; 1672955 ) [2] =&gt; stdClass Object ( [style] =&gt; Array ( [0] =&gt; Alternative Rock [1] =&gt; Goth Rock [2] =&gt; Heavy Metal ) [thumb] =&gt; http://api.discogs.com/image/R-90-2785283-1300918365.jpeg [format] =&gt; Array ( [0] =&gt; CD [1] =&gt; Compilation [2] =&gt; Unofficial Release ) [country] =&gt; Russia [title] =&gt; HIM (2) - Overload Hits [uri] =&gt; /HIM-Overload-Hits/release/2785283 [label] =&gt; Array ( [0] =&gt; FullHouse Records ) [catno] =&gt; F????? [year] =&gt; 2003 [genre] =&gt; Array ( [0] =&gt; Rock ) [resource_url] =&gt; http://api.discogs.com/releases/2785283 [type] =&gt; release [id] =&gt; 2785283 ) [3] =&gt; stdClass Object ( [style] =&gt; Array ( [0] =&gt; Drone [1] =&gt; Ambient ) [thumb] =&gt; http://api.discogs.com/image/R-90-3108621-1316178067.jpeg [format] =&gt; Array ( [0] =&gt; CDr [1] =&gt; Album [2] =&gt; Limited Edition ) [country] =&gt; Russia [title] =&gt; Solar Ocean - Twillight October [uri] =&gt; /Solar-Ocean-Twillight-October/release/3108621 [label] =&gt; Array ( [0] =&gt; Necrophone ) [catno] =&gt; F [year] =&gt; 2010 [genre] =&gt; Array ( [0] =&gt; Electronic ) [resource_url] =&gt; http://api.discogs.com/releases/3108621 [type] =&gt; release [id] =&gt; 3108621 ) [4] =&gt; stdClass Object ( [style] =&gt; Array ( [0] =&gt; Techno [1] =&gt; Electro [2] =&gt; Tech House [3] =&gt; Minimal ) [thumb] =&gt; http://api.discogs.com/image/R-90-699054-1161976299.jpeg [format] =&gt; Array ( [0] =&gt; Vinyl [1] =&gt; 12" [2] =&gt; Box Set [3] =&gt; Compilation [4] =&gt; Limited Edition ) [country] =&gt; Germany [title] =&gt; Various - Cocoon Compilation F [uri] =&gt; /Various-Cocoon-Compilation-F/master/33655 [label] =&gt; Array ( [0] =&gt; Cocoon Recordings [1] =&gt; Cocoon Compilation ) [catno] =&gt; COR LP 011 [year] =&gt; 2006 [genre] =&gt; Array ( [0] =&gt; Electronic ) [resource_url] =&gt; http://api.discogs.com/masters/33655 [type] =&gt; master [id] =&gt; 33655 ) ) ) &lt;/pre&gt; </code></pre> <p>which is exactly correct and i can see all the data i want to, however when i try to access the (lets say thumbnail of the first) like so:</p> <pre><code>echo $discogsJSON['results']['0']['thumb']; </code></pre> <p>i am left with: <code>Fatal error: Cannot use object of type stdClass as array</code></p> <p>I suppose from here there is enough information to go off of to construct the correct echo statement, but can anyone explain to me the OO theory behind the correct way to get the data out?</p>
    singulars
    1. This table or related slice is empty.
    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