Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xml可以转换为任何json格式吗_Xml_Json_D3.js - Fatal编程技术网

xml可以转换为任何json格式吗

xml可以转换为任何json格式吗,xml,json,d3.js,Xml,Json,D3.js,我尝试使用d3.js树布局,它只使用特定格式的输入json。比如说 { "name": "Base", "children": [ { "name": "Type A", "children": [ { "name": "Section 1", "children": [ {"name": "Child 1"},

我尝试使用d3.js树布局,它只使用特定格式的输入json。比如说

{
"name": "Base",
"children": [
    {
        "name": "Type A",
        "children": [
            {
                "name": "Section 1",
                "children": [
                    {"name": "Child 1"},
                    {"name": "Child 2"},
                    {"name": "Child 3"}
                ]
            },
            {
                "name": "Section 2",
                "children": [
                    {"name": "Child 1"},
                    {"name": "Child 2"},
                    {"name": "Child 3"}
                ]
            }
        ]
    }

  ]
};
我也指的是这个小提琴的例子 我想知道的是,是否可以使用javascript将xml数据转换为任何格式的json

生成的xml如下所示:

<universe>
 <universename>unique</universename>
 <creator>god</creator>
 <planets>
   <planetname>earth</planetname>
   <position>third</position>
   <countries>
     <countryname>country-1</countryname>
     <countrypopulation>xxx</countrypopulation>
   </countries>
   <waterbodies>
     <ocean>
       <oceanname>pacific</oceanname>
     </ocean>
   </waterbodies>
   <mountains>
    <mountainname>everest</mountainname>
   </mountais>
  </planets>

 <planets>
   <planetname>jupiter</planetname>
   <position>fourth</position>
   <countries>
     <countryname>country-2</countryname>
     <countrypopulation>xxx</countrypopulation>
   </countries>
   <waterbodies>
     <ocean>
       <oceanname>pacific-1</oceanname>
     </ocean>
   </waterbodies>
   <mountains>
    <mountainname>everest-2</mountainname>
   </mountais>
  </planets>  

</universe>

是的,您可以将XML转换为JSON,这是David Walsh的一篇文章,详细介绍了这一点。

是的。。。你有具体问题吗?是的,我有,我会告诉你一点细节。当你有问题时,我会编辑我的问题,请把“我”也改成“我”,因为在英语中,没有“我”这个词。它们真的伤了我的眼睛…我很困惑。jqtree不接受JSON并将其转换为HTML吗?在这种情况下,您不能使用您创建的JSON来表示树并对其进行操作吗?不,我有一个独立的html表单,它在提交时创建一个xml文件。现在我需要用图形格式表示这些数据。因此,这就是我选择使用d3.js的原因
{
    "name": "universe",
    "value_list": [
        {
            "name": "universename",
            "value": "unique"
        },
        {
            "name": "creator",
            "value": "god"
        }
    ],
    "children": [
        {
            "name": "planets",
            "value_list": [
                {
                    "name": "planetname",
                    "value": "earth"
                },
                {
                    "name": "position",
                    "value": "third"
                }
            ],
            "children": [
                {
                    "name": "countries",
                    "value_list": [
                        {
                            "name": "countryname",
                            "value": "country-1"
                        },
                        {
                            "name": "countrypopulation",
                            "value": "xxx"
                        }
                    ]
                },
                {
                    "name": "waterbodies",
                    "children": [
                        {
                            "name": "ocean",
                            "value_list": [
                                {
                                    "name": "oceanname",
                                    "value": "pacific"
                                }
                            ]
                        }
                    ]
                },
                {
                    "name": "mountains",
                    "value_list": [
                        {
                            "name": "mountainname",
                            "value": "everest"
                        }
                    ]
                }
            ]
        },
        {
            "name": "planets",
            "value_list": [
                {
                    "name": "planetname",
                    "value": "jupiter"
                },
                {
                    "name": "position",
                    "value": "fourth"
                }
            ],
            "children": [
                {
                    "name": "countries",
                    "value_list": [
                        {
                            "name": "countryname",
                            "value": "country-2"
                        },
                        {
                            "name": "countrypopulation",
                            "value": "xxx"
                        }
                    ]
                },
                {
                    "name": "waterbodies",
                    "children": [
                        {
                            "name": "ocean",
                            "value_list": [
                                {
                                    "name": "oceanname",
                                    "value": "pacific-1"
                                }
                            ]
                        }
                    ]
                },
                {
                    "name": "mountains",
                    "value_list": [
                        {
                            "name": "mountainname",
                            "value": "everest-2"
                        }
                    ]
                }
            ]
        }
    ]
}