PHP中的XML到数组的错误

我试图将XML文件转换为php数组,除了这个节点之外,所有节点都会很好。</ p>

 &lt; category name =“Wheels and Tires”&gt; 
&lt; specification name =“Front Tire Type”&gt; P245 / 40R18&lt; / specification&gt;
&lt; specification name = “前轮直径”> 18.0×8.0&lt; /规格&gt;
&lt;规格名称=“后轮胎类型”&gt; P245 / 40R18&lt; /规格&gt;
&lt;规格名称=“后轮直径”&gt; 18.0 x 8.0&lt; / specification&gt;
&lt; / category&gt;
</ code> </ pre>

问题是属性名称从数组中消失了,不知道为什么,谢谢你提前 ..这是我的代码和数组结果。</ p>

  $ xml = curl_exec($ ch);  // $ result现在包含响应JSON或XML。
$ xml_string = simplexml_load_string($ xml);
$ json = json_encode($ xml_string);
$ xml_parse = json_decode($ json,TRUE);
return( $ xml_parse);

数组:2 [▼
“@attributes”=&gt; array:1 [▶]
“specification”=&gt; 数组:4 [▼
0 =&gt; “P245 / 40R18”
1 =&gt; “18.0 x 8.0”
2 =&gt; “P245 / 40R18”
3 =&gt; “18.0 x 8.0”
]
]
</ code> </ pre>
</ div>

展开原文

原文

Hi I trying to convert an XML file into a php array, all the nodes becomes well except this one.

<category name="Wheels and Tires">
<specification name="Front Tire Type">P245/40R18</specification>
<specification name="Front Wheel Diameter">18.0 x 8.0</specification>
<specification name="Rear Tire Type">P245/40R18</specification>
<specification name="Rear Wheel Diameter">18.0 x 8.0</specification>
</category>

The problem is that the attribute name is gone from the array, any idea why, thank you in advance.. here is my code and the array result.

$xml = curl_exec($ch); // $result now contains the response JSON or XML.
$xml_string = simplexml_load_string($xml);
$json = json_encode($xml_string);
$xml_parse = json_decode($json, TRUE);
return($xml_parse);

  array:2 [▼
    "@attributes" => array:1 [▶]
    "specification" => array:4 [▼
      0 => "P245/40R18"
      1 => "18.0 x 8.0"
      2 => "P245/40R18"
      3 => "18.0 x 8.0"
    ]
  ]

donglin8467
donglin8467 转换为json然后返回是没有意义的:/
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐