javascript - 使用 AngularJS 解析 JSON 文件

标签 javascript json angularjs

我正在尝试解析为我正在开发的应用程序创建的 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/

相关文章:

javascript - 跨多个选择框拆分 JSON 数组

html - Angular.js Controller 无法设置属性

javascript - 按属性查找重复对象并使用 Javascript 或 UnderscoreJS 合并

javascript - 增量变量在我的函数中不起作用

python - 拦截从 iOS 应用程序发送到服务(从 Python 和 Appium)的请求

javascript - AngularJS ng-重复未知的深度数组

asp.net - C# 和 Twitter API : Getting tweets with specific#tag

javascript - HTML5 Canvas 无法正确显示点击次数

javascript 回调函数 onreadystatechange,在一个简单的 ajax 示例中

javascript - 从 MongoDB 在 Angular.js 中显示图像