我正在使用这个库:https ://sourceforge.net/p/wowarmoryapi/home/Home/严重缺乏文档。那里的论坛大多没有答案。
我已经能够成功地从战网的军械库中提取数据,特别是公会信息。然后,它作为一个大 blob存储在wa_guilds表中,位于名为Data的行中。从那里我不确定如何拉它并显示它。我已经尝试了下面的代码以及大约 100 种不同的变体以及反序列化,但我太缺乏经验了。这只是超出了我的知识水平。
我的错误:注意:未定义的索引: 我尝试过的对象名称、级别、排名
由print $roster->character引起的新错误;:“注意:试图获取非对象的属性”
我的代码:
<?php
include('_inc.php'); // shh I'm hunting wabbits
$conn = mysqli_connect("localhost", "root", "")
or die(mysql_error());
mysqli_select_db($conn, "wow")
or die(mysql_error());
$data = mysqli_query($conn, "SELECT Data FROM wa_guilds") or die(mysql_error());
//echo $data;
print "<table border cellpadding=3>";
while($info = mysqli_fetch_array( $data, MYSQLI_BOTH ))
{
$roster = json_decode($info[0]);
print $roster->character;
}
print "</table>";
//$array = explode(',', $data);
//echo $array[0];
?>
它看起来像一个受欢迎的图书馆,所以我希望有人有经验。
来自 var_dump 的一些数据:
array(2) { [0]=> string(100000) "{"lastModified":1367433943000,"name":"Teh Fail","realm":"Zul'jin","battlegroup":"Ruin"," level":25,"side":1,"achievementPoints":1195, [{"character":{"name":"Mundi","realm":"Zul'jin","battlegroup":"Ruin", "class":8,"race":8,"gender":0,"level":85,"achievementPoints":12855,"thumbnail":"zuljin/65/3357249-avatar.jpg","guild": "Teh Fail","spec":{"name":"Fire","role":"DPS","backgroundImage":"bg-mage-fire","icon":"spell_fire_firebolt02","description":"用火球和燃烧的火焰点燃敌人。","order":1}},"rank":3},{"character":{"name":"Kekeke","realm":"Zul' jin","battlegroup":"废墟","class":4,"race":8,"gender":0,"level":85,"achievementPoints":11345,"thumbnail":"zuljin/76/ 3359564-avatar.jpg","guild":"Teh Fail","spec":{"name":"Combat","role":"DPS","backgroundImage":"bg-rogue-combat"," icon":"ability_backstab","description":"一个使用敏捷和狡猾与敌人正面交锋的浪荡剑客。","order":1}},"rank":3},{"character" :{"name":"Benth","realm":"祖尔金","battlegroup":"Ruin","class":9,"race":5,"gender":0,"level":90,"成就点数":13165,"thumbnail":"zuljin/252/3364348-avatar.jpg","guild":"Teh Fail","spec":{"name":"Destruction","role":"DPS" ,"backgroundImage":"bg-warlock-destruction","icon":"spell_shadow_rainoffire","description":"一个叫火烧毁敌人的混沌大师。","order":2}}, “排名”:3}"level":90,"achievementPoints":13165,"thumbnail":"zuljin/252/3364348-avatar.jpg","guild":"Teh Fail","spec":{"name":"Destruction", "role":"DPS","backgroundImage":"bg-warlock-destruction","icon":"spell_shadow_rainoffire","description":"一个叫火烧毁敌人的混沌大师。","订单":2}},"排名":3}"level":90,"achievementPoints":13165,"thumbnail":"zuljin/252/3364348-avatar.jpg","guild":"Teh Fail","spec":{"name":"Destruction", "role":"DPS","backgroundImage":"bg-warlock-destruction","icon":"spell_shadow_rainoffire","description":"一个叫火烧毁敌人的混沌大师。","订单":2}},"排名":3}spell_shadow_rainoffire","description":"一个叫火烧毁敌人的混沌大师。","order":2}},"rank":3}spell_shadow_rainoffire","description":"一个叫火烧毁敌人的混沌大师。","order":2}},"rank":3}
编辑: 将 mysqli 数据库连接线更改为 PDO,一切都很好。