【发布时间】:2014-01-02 14:59:00
【问题描述】:
我有问题。 我想用 php scipt 打印出这个字符串在这个 JSON 文件中的字符串: http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy
它是:数据/描述
我希望你明白我的意思。
【问题讨论】:
我有问题。 我想用 php scipt 打印出这个字符串在这个 JSON 文件中的字符串: http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy
它是:数据/描述
我希望你明白我的意思。
【问题讨论】:
使用jsondecode php函数。
$url = 'http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy';
$jsondata = file_get_contents($url); //json data from url
$data = json_decode($jsondata,1); // convert json data to array
echo $data['data']['description']; // access data using keys of array, mapped to properties in json
【讨论】:
$json_uri = 'http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy';
$json = file_get_contents($json_uri);
$data = json_decode($json,1); // convert json data to array
$count = 1;
foreach ($data['data'] as $key => $info) {
echo $count++.' - '.$info['description'].'<br>';
}
【讨论】: