Don Nijssen Don Nijssen - 2 months ago 16
JSON Question

Ionic app reading service object

How can i get the value of "name" in this json string? i tried a lot but it always returns a undefined object back so it means i am doing somthing wrong with the order of values i call.

Thansk for you help in advance.

console gives my this if i JSON.stringify my object

{"data":{"Events":[{"festival_id":"2","name":"Pinkpop","date":"2017-06-03","genre":"Pop/Rock","longitude":"6.0224085","latitude":"50.8927646"}]},"status":200,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://fiestaapp.codesolutions.nl/Api/getEvents.php?id=2","headers":{"Accept":"application/json, text/plain, /"}},"statusText":"OK"}

Answer

I check your JSON response for accessing name attribute from event array you need to use following way

For Example

data.Events[0].name

Because Events is array object otherwise if you need to use ng-repeat and use like following way

 <div ng-repeat="event in events">
   <div class="name">{{event.name}}</div>
 </div>

In controller you need to add following code

 (data){
    $scope.events = data.Events;
 }

Hopes this will help you !!