Javascript 如何使用jquery将xml转换为json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3642789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:33:21 来源:igfitidea点击:
how to convert xml to json using jquery
提问by Bilgin K?l??
The following code runs very well for this test XML page:
下面的代码对于这个测试 XML 页面运行得非常好:
$.get('data/animals.xml', function(xml){
var animals = $.xml2json(xml);
alert(animals.dog[1].name +'/'+ animals.dog[1]);
});
But how can I adapt this code to get the rate data from this European Central Bank page?
但是我如何修改此代码以从这个欧洲中央银行页面获取利率数据?
Reference:
参考:
回答by Zafer
Try the following. I've tested it on FF 3.6 and Chrome 6, it works.
请尝试以下操作。我已经在 FF 3.6 和 Chrome 6 上测试过它,它可以工作。
$.get('data/eurofxref-daily.xml', function(xml) {
var jsonObj = $.xml2json(xml);
alert(jsonObj.Cube.Cube.Cube[0]["rate"]);
});

