I am trying to just get the values of MediaUrl
(meaning just the URL) into an array of strings with JSON on PHP. I want to ignore everything else. Here is what is returning from the URL I call. What do I need to do in PHP to get these values into an array?
{
"d": {
"results": [
{
"__metadata":
{
"uri": "https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='12 monkeys blu-ray'&$skip=0&$top=1",
"type": "ImageResult"
},
"MediaUrl": "http://www.dvdlink.ca/images/Movies%20Covers/9779/47/1250724527_1250911533.jpg",
"Thumbnail": {
"__metadata": {
"type": "Bing.Thumbnail"
},
"MediaUrl": "http://ts4.mm.bing.net/th?id=HN.607991009242185763&pid=15.1",
"FileSize": "10424"
}
},
{
"__metadata": {
"uri": "https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='12 monkeys blu-ray'&$skip=1&$top=1",
"type": "ImageResult"
},
"MediaUrl": "http://www.bluray-dvd-film-shop.at/media/images/popup/12-Monkeys-bluray.jpg",
"Thumbnail": {
"__metadata": {
"type": "Bing.Thumbnail"
},
"MediaUrl": "http://ts4.mm.bing.net/th?id=HN.608017534956014467&pid=15.1",
"FileSize": "17060"
}
}
],
"__next": "https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='12%20monkeys%20blu-ray'&$skip=50"
}
}
$result = array();
$array = json_decode($your_json_string, true);
foreach ($array['d']['results'] as $entry)
$result[] = $entry['MediaUrl'];
Everything you need is not in $result array, and if the are no results (missing MediaUrl), empty($result) will return TRUE.
You can do as
json_decode($data,true);
This will give you an array and you can loop though the array to fetch the data.
$data = 'Your JSON string' ;
Here is the manual http://in2.php.net/json_decode