What’s your existing code?
var res = this.CallRestAPI('https://cors-anywhere.herokuapp.com/https://celebme.ialocation.com/ads',"GET",this.accessToken);
console.log(res.count);
AdManager.prototype.CallRestAPI = function(_url,_method,_accessToken){
var _newMethod=selfclass.Fetch(_url,_method,null,_accessToken);
_newMethod.then(response => {
var main=response.json();
console.error(main);
return main;
}).then(userRepos => {
//console.log("user response is here"+JSON.stringify(userRepos));
console.log("Req Response 1: " + userRepos);
});
};
Have you tried accessing userRepos.ads
?
Yes. It shows same.
What do you mean it shows the same?
I tried to access the attribute "count " from response but it shows an error. cannot read property “count” of null.
Without running the code myself, it looks fine to me. I also did a quick test with some test JSON and that is also fine:
var _newMethod=new Promise((resolve, reject) => {
setTimeout(() => {
resolve('{"userId":1,"id":1,"title":"delectus aut autem","completed":false}');
}, 300);
});
_newMethod.then(response => {
var main = JSON.parse(response);
return main;
}).then(userRepos => {
console.log(userRepos.title);
});
Prints
delectus aut autem
As expected
Add some breakpoints and and inspect the objects directly during each stage of the Promise chain.