0

I am getting the following JSON response:

{
    "systemDefence": 0,
    "sensorsDefence": [{
        "index": 1,
        "defence": 0
    }, {
        "index": 2,
        "defence": 3
    }, {
        "index": 3,
        "defence": 3
    }, {
        "index": 4,
        "defence": 3
    }, {
        "index": 5,
        "defence": 0
    }]
}

With the simplified code i was able to receive and return a response to a web page field. But what i am trying to achieve now is to rename the value for "index" and "defence" with the following formula:

  • 1 - Name1, 2 - Name2, 3 - Name3, etc.
  • 1 - activated, 2 - not activated, 3 - something...., etc

Planned output should look like:

  index : Name1 
defence : activated

  index : Name2 
defence : something

I have used the following script to rename the values but in this case doesn't work anymore:

JSON response:

{
    "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";
        }   
  });
});

Any suggestion/solution is welcome. Thanks in advance!

spedja
  • 1
  • 1
  • I don't understand how looks your json? – IsraGab Apr 09 '16 at 20:49
  • Have you seen this question? http://stackoverflow.com/questions/13391579/how-to-rename-json-key – eikooc Apr 09 '16 at 21:09
  • Yes, i have seen similar solution but i can change only JSON key (in my case only "index", "defence") What i am struggling is to change/replace only values: "1", "2", "3". Thanks! – spedja Apr 14 '16 at 19:40

0 Answers0