Я пытаюсь перебрать строковые данные json с помощью angularjs, но при выводе переменных я получаю неопределенное значение.Мой формат json показан ниже при выборе с консоли
{"data":[
{"id":1,"firstname":"jhfhfh","lastname":"hchch","middlename":null,"dob":"hhc","gender":"hhhhchch","nat":"chhch","phonenumber":null,"idn:"chch",
"email":"yuyu@yahoo.com","username":"cat","password":"password","country":"hshh","state":"hdhdh","city":"hdhdh","address":"area","confirmedEmail":null,"dateOfReg":"hhc"}],
"status":200,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"/up","requestHeaders":{"Accept":"application/json"},
"params":{"email":"yuyu@yahoo.com"},"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"OK"}
, вот моя угловая функция
getData: function (email) {
$http({
method: 'GET',
url: '/up',
requestHeaders: {Accept: 'application/json'},
params: {email: email}
}).then(function successCallback(res) {
if (res.status == 204) {
} else if (res.status == 200) {
var myJSON = JSON.stringify(res);
console.log(myJSON); //prints the data
var variable = '';
var name = '';
angular.forEach(myJSON,function(item) { //attempting to do the iteration here
variable += item.email ;
name += item.username ;
})
alert(variable); //outputs undefined
}
}, function errorCallback(response) {
alert(JSON.stringify(response));
});
}
}
как мне пройти через данные json