I'm playing around learning a bit of REST APIs. I'm going to omit the URL I'm using for privacy purposes. The gist is that I'm receiving a dictionary-type object. The third entry in the dictionary is an array of JSON-like objects. When I try to look at this data through an alert it says:
undefined is not an object
I don't know what I have to do to either typecast it into something usable or format it upon entry.
(function(){
var Info = "";
var exampleData = [{}];
var app = angular.module('transinfo', ["ui.bootstrap.modal","angularjs-dropdown-multiselect"]);
app.controller('PanelController', function($scope,$http){
$http.get("ThisURL gives data")
.then(function(response){
//var info = JSON.parse(response);
exampleData = response.data;
console.log(response.data);
console.log(exampleData);
}).catch(function(data){
});
$scope.example1model = [];
// $scope.example1data = [ {id: 1, label: "David"}, {id: 2, label: "Jhon"}, {id: 3, label: "Danny"} ];
$scope.example1data = exampleData;
alert(exampleData.payload[0]);
Info = "blah";
this.Info = Info;
this.getInfo = function(){
$http.get("this url also gives data")
.then(function(response){
//var info = JSON.parse(response);
this.Info=response.data;
console.log(response.data);
console.log(response.data["success"]);
alert(response.data["payload"][0].CityID);
}).catch(function(data){
this.Info = "Error";
});
};
this.changeInfo = function(){
this.Info = "Changed";
console.log("hey");
};
this.selectTab = function(setTab){
this.tab = setTab;
//this.getInfo();
};
this.isSelected = function(checkTab){
return this.tab === checkTab;
};
});
})();
Here's some sample data I'd receive:
{success: true, message: "", error_code: "", payload: [{CityID: 72, DescriptionES: "Puerto Rico", DescriptionEN: "Puerto Rico"}, {CityID: 999, DescriptionES: "VACIO", DescriptionEN: "EMPTY"}]}