我正在尝试解析为我正在开发的应用程序创建的 JSON 文件。 JSON 文件如下所示:
{"thresholds":[
{"heatIndex":[
{"maxTemp":[{"red":"125","orange":"105","yellow":"90","green":"-80"}]},
{"minTemp":[{"red":"-50","orange":"-35","yellow":"-20","green":"0"}]}
]},
{"wind":[
{"speed":[{"red":"34.8","orange":"26.1","yellow":"17.4","green":"0"}]},
{"gust":[{"red":"50.4","orange":"39.1","yellow":"26.1","green":"0"}]}
]}
]}
我需要让我的 Angular 应用程序为我输出数据,并且一直在尝试按照 http.get 的教程进行操作,但我无法获取我的数据。关于如何格式化我的 Angular 应用程序的这一部分,我需要帮助的基本部分:
<ul>
<li ng-repeat="x in thresholds">
{{x.thresholds}}
</li>
</ul>
</div>
<!-- NG APP Script -->
<script>
var ehwo2App = angular.module('ehwo2App' , []);
ehwo2App.controller('ehwo2Ctrl' , function ($scope, $http) {
$http.get('config.json').success(function(data) {
$scope.thresholds = data;
});
});
</script>
最佳答案
在您的 $http 请求中,尝试将其更改为:
$scope.thresholds = data;
到
$scope.thresholds = data.thresholds;
关于javascript - 使用 AngularJS 解析 JSON 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32528134/