【发布时间】:2014-12-17 12:22:21
【问题描述】:
我正在学习 angularjs。
当我想访问 xml 文件时,我无法做到,我使用了 xml_strjson 此方法将数据 xml 转换为 json 但无法在 html 文件中访问 这是我的代码:
enter code here<!DOCTYPE html>
<html ng-app="">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"> </script>
<script type="text/javascript" src="http://demos.amitavroy.com/learningci/assets /js/xml2json.js" charset="UTF-8"></script>
<script>
function customersController($scope, $http) {
$http.get("http://localhost:13087/Data.xml")
.success(function (response) {
$scope.lstComapanies = x2js.xml_str2json(response);
console.log($scope.lstComapanies);
alert(response);
});
}
</script>
<title></title>
</head>
<body ng-controller="customersController">
<table>
<tbody>
<tr ng-repeat="CompanyModel in lstComapanies">
<!-- $index for duplicate values -->
<td class="border">
<label>{{ CompanyModel }}</label>
</td>
</tr>
</tbody>
</table>
我的 json 数据
{
"__cnt": 8,
"CompanyModel": [
{
"__cnt": 7,
"BacklogSum": "646",
"BacklogSum_asArray": [
"646"
],
"BillingSum": "607",
"BillingSum_asArray": [
"607"
],
"BookingSum": "646",
"BookingSum_asArray": [
"646"
],
"CashflowSum": "$-4809038.45",
"CashflowSum_asArray": [
"$-4809038.45"
],
"LstCompanies": {
"__cnt": 1,
"_i:nil": "true"
},
"LstCompanies_asArray": [
{
"__cnt": 1,
"_i:nil": "true"
}
],
"Name": "OPTERNA AM, INC. ",
"Name_asArray": [
"OPTERNA AM, INC. "
],
"Number": "2000",
"Number_asArray": [
"2000"
]
}
],
"_xmlns:i": "http://www.w3.org/2001/XMLSchema-instance",
}
【问题讨论】:
-
尝试解析 JSON.parse(your_converted_data) 。