Reputation: 392
I want to use PHP to parse JSON data from an external site. This code is working as intended:
$json = file_get_contents($url);
$obj = json_decode($json);
... and
echo $obj->title;
... is posting the title from the JSON data (Far Cry Primal):
{"id":241408,"title":"Far Cry Primal","url":"http:\/\/www.prisguide.no\/produkt\/far-cry-primal-241408","price":547,"priceCount":13,"image":{"100x100":"http:\/\/img.prisguide.no\/1678\/1678079\/original.77x100mt.jpg","300x300":"http:\/\/img.prisguide.no\/1678\/1678079\/original.232x300t.jpg","500x500":"http:\/\/img.prisguide.no\/1678\/1678079\/original.jpg"},"category":"Spill","categoryId":32,"manufacturer":"Ubisoft Montreal","specifications":"Xbox One, Action, 18+, Ubisoft","specificationsFull":[{"id":96,"name":"Plattform","type":"select","sectionName":"Generelt","value":[{"id":45275,"value":"Xbox One"}]}
But I need to access more elements, like the last one (scroll all the way to the right) - value: Xbox One.This has it's own ID, but im not sure how to access it.
Any hints?
Upvotes: 0
Views: 313
Reputation: 178
Try something like this, your JSON isn't valid so I can't test it but I'm sure you get the idea.
foreach($obj as $items)
{
foreach($items as $item)
{
foreach($item as $value)
{
foreach($value as $key => $value)
{
echo $key . ': ' . $value;
echo '<br>';
}
}
}
}
Upvotes: 1