gpt4 book ai didi

php - SimpleXML 解析 WoWArmory 属性的问题

转载 作者:可可西里 更新时间:2023-11-01 00:11:26 24 4
gpt4 key购买 nike

这是一个示例项目:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com