Adam
Adam

Reputation: 20882

PHP json_decode + Print Array Values Fails

 stdClass Object ( [free] => 100% δωρεάν [meetsingles] => Γνωρίστε Singles [searchprofiles] => Προφίλ Αναζήτηση )

I have a JSON array that after decoded 'json_decode' and printed to screen it looks like above - using UTF8 for Greek.

This is how I print it:

$siteLanguages = json_decode($result);
print_r($siteLanguages);

When I try to access one of the values the page displays only until the point of the print and then it stops loading - eg: like half a page will show - comment this out and the whole page shows - below is how I'm trying:

 print $siteLanguages['searchprofiles'];

I can't see why I can't use the associate array like any other.

Is there a trick I'm missing here? Should the decoded json array show 'stdClass Object' when printed?

thx

Upvotes: 0

Views: 1078

Answers (2)

goyem
goyem

Reputation: 11

The right way is this: $siteLanguages = json_decode($result,true); will get an array,your way get an object;

Upvotes: 1

Sergey Ratnikov
Sergey Ratnikov

Reputation: 1296

I think you're dealing with an object, not array

print $siteLanguages -> searchprofiles;

Upvotes: 2

Related Questions