How to access a value of JSON response

actually i want to get senderNewCall from the whole jsone response

below my code.

.subscribe(data => {
        let leaddetails = data.json();
        this.leaddetailsvalue =leaddetails.viewleaddetails;
        this.data = leaddetails.userMobile;
        alert(this.data)
      }, error => {
        //console.log(error);// Error getting the data
        alert("No Internet connection!")
      });

json response

{"details": [{"userID":"1","userName":"Monojit Roy","userMobile":"3232","userEmailid":"monojit
@flycoders.com","userPaswrd":"monojit","leadID":"1","senderNewCall":"55","senderGreenCall":"8","senderYellowCall"
:"5","senderFollowUpCall":"2","sendDate":""},{"userID":"1","userName":"Monojit Roy","userMobile":"3232"
,"userEmailid":"monojit@flycoders.com","userPaswrd":"monojit","leadID":"5","senderNewCall":"14","senderGreenCall"
:"3","senderYellowCall":"5","senderFollowUpCall":"6","sendDate":""},{"userID":"1","userName":"Monojit
 Roy","userMobile":"3232","userEmailid":"monojit@flycoders.com","userPaswrd":"monojit","leadID":"6","senderNewCall"
:"99","senderGreenCall":"15","senderYellowCall":"35","senderFollowUpCall":"20","sendDate":"22-11-2017"
}]}

please guide me

let leaddetails =JSON.stringify(data.details);

console.log(leaddetails.senderNewCall);

Showing this error.
ERROR
TypeError: leaddetails is undefined

declare leaddetails varible globally.

leaddetails :any;

this.leaddetails =JSON.stringify(data.details);

still showing error.

can you show me your ts code ?

ionViewDidLoad()  {
 
     this.http.get(this.URL+this.userID)
     
      .subscribe(data => {
       this.leaddetails =JSON.stringify(data.viewleaddetails);
        alert(this.leaddetails.senderNewCall);
      }, error => {
        //console.log(error);// Error getting the data
        alert("No Internet connection!")
      });

  }

and i’m details change to viewleaddetails

JSON response

{"viewleaddetails": [{"userID":"3","userName":"Sourav Halder","userMobile":"7003647070","userEmailid"
:"sourav@flycoders.com","userPaswrd":"sourav","leadID":"7","senderNewCall":"98","senderGreenCall":"45"
,"senderYellowCall":"25","senderFollowUpCall":"34","sendDate":"22-11-2017"},{"userID":"3","userName"
:"Sourav Halder","userMobile":"7003647070","userEmailid":"sourav@flycoders.com","userPaswrd":"sourav"
,"leadID":"8","senderNewCall":"85","senderGreenCall":"45","senderYellowCall":"26","senderFollowUpCall"
:"11","sendDate":"22-11-2017"}]}

ok i forget to parse json data

this.leaddetails = JSON.parse(JSON.stringify(data[“viewleaddetails”]));

try this

Hello there!

Could you please share more information about your code?

this.leaddetails is array of json. so, you’ll have to use for loop to get senderNewCall value for all entries.

ionViewDidLoad()  {
 
     this.http.get(this.URL+this.userID)
     
      .subscribe(data => {
       this.leaddetails = data.viewleaddetails;
       for(var i = 0; i < this.leaddetails.length; i++){
             console.log(this.leaddetails[i].senderNewCall); //here you'll get sendernewcall value for all entry
       }
      }, error => {
        //console.log(error);// Error getting the data
        alert("No Internet connection!")
      });

  }

when put this above line showing this error.

@Ankit_Makwana when put your code showing this error.

ya i have fixed my problem thank you.

@Ankit_Makwana just you forgot to put this line let leaddetails = data.json();

now its working fine.thank you for your valuable reply

.subscribe(data => {
        let leaddetails = data.json();
        this.leaddetails = leaddetails.viewleaddetails;
       for(var i = 0; i < this.leaddetails.length; i++){
             alert(this.leaddetails[i].senderNewCall); //here you'll get sendernewcall value for all entry
       }
      }, error => {
        //console.log(error);// Error getting the data
        alert("No Internet connection!")
      });

Thanks to all for your quick response.

Ohh…my mistake…Good that you got your solution. :grinning: