[英]Convert XML url to JSON url in AngularJS
有沒有一種方法可以將XML url轉換為JSON url,以便可以在我的網站中使用它?
{"breakfast_menu": {
"food": [
{
"name": "Belgian Waffles",
"price": "$5.95",
"description": "Two of our famous Belgian Waffles with plenty of real maple syrup",
"calories": "650"
},
{
"name": "Strawberry Belgian Waffles",
"price": "$7.95",
"description": "Light Belgian waffles covered with strawberries and whipped cream",
"calories": "900"
},
{
"name": "Berry-Berry Belgian Waffles",
"price": "$8.95",
"description": "Light Belgian waffles covered with an assortment of fresh berries and whipped cream",
"calories": "900"
},
{
"name": "French Toast",
"price": "$4.50",
"description": "Thick slices made from our homemade sourdough bread",
"calories": "600"
},
{
"name": "Homestyle Breakfast",
"price": "$6.95",
"description": "Two eggs, bacon or sausage, toast, and our ever-popular hash browns",
"calories": "950"
}
]}}
假設該URL為http://www.w3schools.com/xml/simple.xml,那么如何將其轉換為JSON,以便可以在AngularJS中使用它
您可以使用xml2json.js將XML轉換為JSON
請務必閱讀xml.com上的隨附文章 ,其中詳細介紹了有關這些轉換的有趣問題。
用法:
$scope.xml = '<breakfast_menu>'+
'<food>'+
'<name>Belgian Waffles</name>'+
'<price>$5.95</price>'+
'</food>'+
'</breakfast_menu>';
var dom = parseXml($scope.xml);
$scope.json = xml2json(dom," ");
使用{{json}}
在您的視圖中顯示json!
{ "breakfast_menu":{"food":{ "name":"Belgian Waffles", "price":"$5.95" }} }
這是一個工作的朋克
@SFDC:嗨...此xml鏈接(' http://www.webservicex.com/globalweather.asmx/GetCitiesByCountry ')可以從xml轉換為json格式
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.