我有一个 XML文件,其中包含以下内容: directory app titleCarrot/title urlwww.carrot.com/url /app app titleCucumber/title urlwww.cucumber.com/url /app/directory 假设我能够读取它并将内容存储为字符串: s = 'dire
<directory> <app> <title>Carrot</title> <url>www.carrot.com</url> </app> <app> <title>Cucumber</title> <url>www.cucumber.com</url> </app> </directory>
假设我能够读取它并将内容存储为字符串:
s = '<directory><app><title>Carrot</title><url>www.google.com</url></app><app><title>Cucumber</title><url>www.cucumber.com</url></app></directory>';
如何将其转换为JavaScript对象,如下所示?
{ "directory": { "app": [ { "title": "Carrot", "url": "www.carrot.com" }, { "title": "Cucumber", "url": "www.cucumber.com" } ] } }我用这个插件… http://www.thomasfrank.se/xml_to_json.html
它总是为我带来魅力.