我发现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”:[],“artworkUrl512”:“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'];
你能帮我解决一下如何提取图标图片的网址吗?
答案 0 :(得分:4)
$data
是json编码的。使用json_decode()
:
答案 1 :(得分:-1)
$data = json_decode($json, true);
echo $data['results'][0]['artworkUrl512'];