作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是一个示例项目:
SimpleXMLElement Object
(
[@attributes] => Array
(
[displayInfoId] => 62116
[durability] => 100
[gem0Id] => 41401
[gem1Id] => 40123
[gem2Id] => 0
[gemIcon0] => inv_jewelcrafting_shadowspirit_02
[gemIcon1] => inv_jewelcrafting_gem_37
[icon] => inv_helmet_98
[id] => 48592
[level] => 245
[maxDurability] => 100
[name] => Liadrin's Headpiece of Triumph
[permanentEnchantIcon] => ability_warrior_shieldmastery
[permanentEnchantItemId] => 44876
[permanentenchant] => 3819
[pickUp] => PickUpLargeChain
[putDown] => PutDownLArgeChain
[randomPropertiesId] => 0
[rarity] => 4
[seed] => 0
[slot] => 0
)
)
我正在尝试为每个项目获取一个 JSON 对象,但大约有 17 个左右,如果我尝试 json_encode()
,它会给我“@attributes”作为包含所有内容的对象我想要的东西。帮忙?
最佳答案
像这样:
<?php
$sxm = new SimpleXMLElement("<a name=\"kkk\" other=\"foo\"/>");
$attrs = $sxm->attributes();
var_dump(json_encode(reset($attrs)));
给出:
string(28) "{"name":"kkk","other":"foo"}"
您遇到的问题是因为 $xmlObj->attributes()
返回一个 SimpleXMLElement
,当转换为数组时,它是一个带有键“@”的数组attributes"和一个带有数组的值,该数组实际上具有作为 (name => value) 对的属性。
关于php - SimpleXML 解析 WoWArmory 属性的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4083182/
我正在开发一个简单的应用程序,它从 wowarmory.com 获取一些数据。我需要做的是获取角色的声望。我知道 api 位于何处: http://www.wowarmory.com/characte
这是一个示例项目: SimpleXMLElement Object ( [@attributes] => Array ( [displayInfoId]
我是一名优秀的程序员,十分优秀!