1

我发现 App Store API 支持有关应用程序的附加信息。

$keyword = $this->input->post('keyword');
$appstore_api = 'http://itunes.apple.com/search?country=US&entity=software&term='.$keyword;
$data = file_get_contents($appstore_api);
echo $data;

这是我编写的 PHP 代码。

我得到这个结果。

{ "resultCount":50, "results": [ {"kind":"software", "features":[], "supportedDevices":["all"], "isGameCenterEnabled":false, "artistViewUrl":"http ://itunes.apple.com/us/artist/burbn-inc./id389801255?uo=4", "artworkUrl60":"http://a2.mzstatic.com/us/r1000/105/Purple/v4/ f3/0e/e2/f30ee271-c564-ec21-02d6-d020bd2ff38b/Icon.png", "screenshotUrls":["http://a3.mzstatic.com/us/r1000/102/Purple/v4/2d/25 /d3/2d25d348-74e9-8365-208c-45e64af73ed6/mzl.xnvocmpt.png”, “http://a1.mzstatic.com/us/r1000/077/Purple/v4/04/18/b3/0418b375-c0c1 -18c1-1aef-07555c99af46/mzl.pkthtqtv.png”, “http://a2.mzstatic.com/us/r1000/069/Purple/v4/31/08/65/31086528-2f37-bca0-71f3-c3095e698f35 /mza_8774562250786021670.png", "http://a3.mzstatic.com/us/r1000/091/Purple/v4/95/a2/65/95a265bb-b9f0-8732-9fe4-823ffbc9aba0/mza_5807950548098772841.png"], "ipadScreenshotUrls":[], " artUrl512":"http://a4.mzstatic.com/us/r1000/089/Purple/v4/44/76/7f/44767fb5-4cb2-25bf-5361-25138b8c2aeb/mzl.ntalagmr.png",

问题是如何提取名为“artworkUrl512”的变量?

我试过这样但失败了。

$image_url = $data->results->artworkUrl512;
$image_url2 = $data['results']['artworkUrl512'];

你能帮我如何提取图标图像网址吗?

4

2 回答 2

4

$data是json编码的。使用json_decode()

http://php.net/manual/en/function.json-decode.php

于 2012-08-02T18:39:58.077 回答
-1
$data = json_decode($json, true);
echo $data['results'][0]['artworkUrl512'];
于 2015-08-22T14:09:46.280 回答