我收到以下JSON响应:
{
"systemDefence": 0,
"sensorsDefence": [{
"index": 1,
"defence": 0
}, {
"index": 2,
"defence": 3
}, {
"index": 3,
"defence": 3
}, {
"index": 4,
"defence": 3
}, {
"index": 5,
"defence": 0
}]
}
通过简化的代码,我能够接收并返回对网页字段的响应。但我现在想要实现的是使用以下公式重命名“index”和“defense”的值:
计划输出应如下所示:
index : Name1
defence : activated
index : Name2
defence : something
我使用以下脚本重命名值,但在这种情况下不再起作用:
JSON回复:
{
"temperature": 23,
"light": 0,
"noisy": 0,
"air": 0,
"humidity": 43.300000
}
<div ng-app="myApp" ng-controller="myCtrl">
Temperature : {{content.temperature}}
Humidity : {{content.humidity}}
Air : {{output_air}}
</div>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("URL")
.then(function(response) {
$scope.content = response.data;
if($scope.content.air == "0"){
$scope.output_air = "excellent";
}
else if($scope.content.air == "1"){
$scope.output_air = "good";
}
else{
$scope.output_air = "bad";
}
});
});
欢迎提出任何建议/解决方案。 提前谢谢!