Javascript 在AngularJS中将XML url转换为JSON url

Javascript 在AngularJS中将XML url转换为JSON url,javascript,json,xml,angularjs,Javascript,Json,Xml,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" }, {

有没有办法将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是这样给出的,那么如何将其转换为JSON,以便在AngularJS中使用它,您可以使用它将XML转换为JSON

请务必阅读,其中详细介绍了这些转换的有趣问题

用法:

  $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,"  ");

这里有一个正在工作的

@SFDC:Hi。。。这个xml链接(“”)可以在$scope中从xml转换为json格式。xml我可以访问url而不是DataOf吗?当然,你只需要使用
$http
服务并获得
xml
对不起,前面的评论是plunker@RamanaUday:嗨..我检查了你的plunker..发现了以下问题。-首先,请参阅控制台以了解此错误。请求的资源上不存在“Access Control Allow Origin”头。这是一个CORS问题。其次,您正在尝试执行
$scope.xml=$http.get(“…”)
$http.get
服务返回承诺,而不是响应数据本身。因此,您不能直接将其分配给变量。以下是更新后的。我已从更改为url以使其正常工作。关于CORS问题,请参见。希望有帮助:)
{ "breakfast_menu":{"food":{ "name":"Belgian Waffles", "price":"$5.95" }} }