1

This code is supposed to return the value of /architecture/building_occupant/buildings_occupied from the Json Freebase file, but it doesn't do anything.

   <?php
    $url = "https://www.googleapis.com/freebase/v1/topic/en/barack_obama?filter=all";
    $json = file_get_contents($url);
    $json = str_replace('/', 'www', $json);
    $json = str_replace('_', 'www', $json);
    $data = json_decode($json, TRUE);
    echo $data->property->wwwarchitecturewwwbuildingwwwoccupantwwwbuildingswwwoccupied->values->text;
    ?>

I don't seem to get an error message, either...

please assist, and thank you!

2 Answers 2

2

You are accessing the object as an array ! You should change your statement like this.

$data = json_decode($json); //<--- Remove the TRUE , Adding TRUE will turn it into an array.
Sign up to request clarification or add additional context in comments.

3 Comments

I've done many a dumb things in my life, but this might be the dumbest. Thanks a lot. :)
@user55335 and this is just funny... wwwarchitecturewwwbuildingwwwoccupantwwwbuildingswwwoccupied
I know it is, I'm just quickly (dirtily) trying to test something, though I know there is never an excuse for fugly code :) @jycr753
0

$data is an array when you use json_decode($json, TRUE)

Use:

$data['property']['wwwarchitecturewwwbuildingwwwoccupantwwwbuildingswwwoccupied']['values']['text']

to output the data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.