Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

JSON array I am getting after get API call, I am getting following json response.

"{"reactions":[{"severity":{"label":"Severe"},"label":"Skin Rash"}],"audit":{"source":"medicare","createDate":"2015-03-02T18:39:23Z","update‌​Date":"2015-03-02T18:39:23Z","version":"1"},"label":"Other - IODINE","ended":"2007-10-28T00:00:00-04:00","started":"1993-01-01T00:00:00-05:00‌​","date":"2015-03-02T18:37:42Z"}". And I need to just display only

":[{"severity":{"label":"Severe"},"label":"Skin Rash"}]" in li tag. How can I do that ?

I need to populate this json array in <li> in html5. How can I do it? I am using restangular.:

Angular JS file:

Restangular.one('APIName', Parameter_to_api).get().then(function (result) {

  $scope.datalist= result;
}

HTML file

<ul class="links">
   <li ng-repeat="data in datalist"></li>                   
</ul>
share|improve this question
    
This is my HTML file: <div class="row"> <div class="col-xs-12"> <ul class="links"> <li ng-repeat="data in datalist"></li> </ul> </div> </div> –  user1528581 22 hours ago
1  
How can I do it ... which part of the process are you having problems with? Question is not very clear –  charlietfl 22 hours ago
    
@charlietfl: after making API call I am getting response as a json array. Which I have mentioned in the question. I need to populate that json array in to <li> tag. How can I do that. Json response format I have mentioned in question. How I am trying to do that I have explained. Sorry. –  user1528581 22 hours ago
    
I don't see anything wrong with the code posted. However, I also don't see any mention of what is expected, or what is being seen instead of expected. –  Claies 22 hours ago
    
You are already doing it, you just need to set datalist to whichever array you want. Right now it's being set to an object. So change it to $scope.datalist = result.data1 or something –  ribsies 22 hours ago

1 Answer 1

Try this

var app = angular.module('app', []);

app.controller('firstCtrl', function($scope) {

  $scope.datalist = {
    data1: [2, 3, 4],
    data2: [6, 7, 8, ],
    data4: [9, 10, 12]
  }

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="app">
  <div ng-controller="firstCtrl">

    <ul class="links" ng-repeat="data in datalist">
      <li ng-repeat="i in data">{{i}}</li>
    </ul>

  </div>
</body>

share|improve this answer
    
Thanks @sylwester. It is working now. –  user1528581 21 hours ago
    
Hi @sylwester: Additional question. Now req. change. I am getting following json response. "{"reactions":[{"severity":{"label":"Severe"},"label":"Skin Rash"}],"audit":{"source":"medicare","createDate":"2015-03-02T18:39:23Z","update‌​Date":"2015-03-02T18:39:23Z","version":"1"},"label":"Other - IODINE","ended":"2007-10-28T00:00:00-04:00","started":"1993-01-01T00:00:00-05:00‌​","date":"2015-03-02T18:37:42Z"}". And I need to just display ":[{"severity":{"label":"Severe"},"label":"Skin Rash"}]" in li tag. How can I do that ? –  user1528581 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.