将XML转换为JSON并将其强制转换为数组

时间:2016-01-10 22:41:19

标签: php json xml

我怎样才能做到这一点:http://www.newtonsoft.com/json/help/html/ConvertXmlToJsonForceArray.htm但是在PHP?

我的意思是,现在我的JSON只有{}括号。当有特定的xml标签

时,我需要[]括号

我有

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <name>xfvxvxffxv</name>
    <fullpaths>
        <name>main_table</name>
        <fullpaths>
            <name>banutoor</name>
            <fullpaths>
                <name>agu12</name>
                <size>3</size>
            </fullpaths>
            <fullpaths>
                <name>agu88</name>
                <size>3</size>
            </fullpaths>
            <fullpaths>
                <name>igu77</name>
                <size>67</size>
            </fullpaths>
            <fullpaths>
                <name>igu</name>
                <size>1288</size>
            </fullpaths>
        </fullpaths>
    </fullpaths>
</root>

这就是我现在这样做的原因:

$xmlP = trim(str_replace('"', "'", $xmlP));
$simple = simplexml_load_string($xmlP);
$json = json_encode($simple);

<fullpaths>我需要

"name": "xfvxvxffxv",
   "fullpaths": [ ......
在JSON中

现在是:

"name": "xfvxvxffxv",
    "fullpaths": {

0 个答案:

没有答案