【发布时间】:2015-11-10 17:46:29
【问题描述】:
以下 html 因 @ 符号而中断。除了不使用 @ 符号之外,还有什么解决方法。我必须使用 @ 符号,因为 json 将通过使用来自 xml 的 newtonsoft jsonconvert http://www.newtonsoft.com/json 在 c# web api 中生成。 jsonconvert 在生成的 json 中使用 @ 符号为 xml 属性添加前缀。
如何解决@符号问题?对我有用的一件事是 message.root.node1["@attr1"]。如果可能,请提供详细说明角度变量/表达式中禁止使用哪些符号的资源。
<html ng-app="countryApp">
<head>
<meta charset="utf-8">
<title>Angular.js JSON Fetching Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script>
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http) {
$scope.message = { "root": { "node1": { "@attr1": "1", "@attr2": "2" }, "node2": { "@attr1": "3", "@attr2": "4" } } }
});
</script>
</head>
<body ng-controller="CountryCtrl">
<h2>Angular.js JSON Fetching Example</h2>
<span>
menudatetime {{message.root.node1.@attr1}}
</span>
</body>
</html>
【问题讨论】:
-
谷歌搜索任何带有@符号的东西都非常烦人。有什么建议吗?
标签: javascript c# json angularjs json.net