我想解析一個JSON文件,我爲我正在創建的應用程序創建。 JSON文件看起來是這樣的:用AngularJS解析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"}]}
]}
]}
我需要讓我的角度應用輸出的數據對我和一直在試圖遵循http.get教程,我不能讓我的數據出來。基本的一部分,我需要怎麼我的角度應用程序的該部分格式的幫助:在您的$ HTTP請求
<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>
$ scope.thresholds = JSON.parse(data); (因爲數據是即將到來的字符串我想)問你的朋友谷歌之前發佈問題http://stackoverflow.com/questions/4935632/parse-json-in-javascript –
@DmitriAlgazin實際上你不必這樣做,角度自動爲你解析json。除非你知道你是對的,否則試着在評論時不要低估。 –