0

我在启动“氏族社区统计”项目时遇到了问题。我有一个带有统计 API 的URL ,我想使用简单的 html dom 解析器在数组中显示它。我想得到这个效果:

{
  "status": "ok", 
  "count": 1, 
  "data": {
    "1": {
      "members_count": 100, 
      "description": "Закрытый клан...", 
      "description_html": "<p>Закрытый клан....\n</p>", 
      "created_at": 1293024672, 
      "updated_at": 1375930001, 
      "name": "Wargaming.net", 
      "abbreviation": "WG", 
      "emblems": {
        "large": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64.png", 
        "small": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_24x24.png", 
        "medium": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_32x32.png", 
        "bw_tank": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64_tank.png"
      }, 
      "clan_id": 1, 
      "members": {
        "196632": {
          "created_at": 1293126248, 
          "role": "private", 
          "updated_at": 1375930001, 
          "account_id": 196632, 
          "account_name": "Wrobel"
        }, 
        "18458": {
          "created_at": 1360836543, 
          "role": "diplomat", 
          "updated_at": 1375930001, 
          "account_id": 18458, 
          "account_name": "alienraven"
        }, 
        "3100": { ....
        }
      }, 
      "motto": "Орлы! Орлицы!", 
      "clan_color": "#e18000", 
      "owner_id": 1277137
    }
  }
}

我的代码

include('simple_html_dom.php');
$html = file_get_html('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659');
...?

接下来我应该做什么来准备一个数组并以我想要的方式在我的网页上显示它?有人有义务向我解释吗?请。

问候玛丽

4

2 回答 2

-1

我看到数据是json格式的。只需使用:

$json  =  file_get_contents('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659'); //gets the json
$obj = json_decode($json); //decode the json into object or array. You'll get an object
var_dump($obj); //view the object. Parse the object the way you want to.
于 2013-09-24T10:13:13.917 回答
-1

尝试这个

<?php
// example of how to modify HTML contents
include('../simple_html_dom.php');

// get DOM from URL or file
$html = file_get_html('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659');

$data = json_decode($html);

echo "<pre>";
print_r($data);
?>
于 2013-09-24T10:14:43.453 回答