Reputation: 319
I want to channel_name_1 automatically increase and go channel_name_2 , channel_name_3 ; if statement where it go
Look to //THİS LİNE
"{\"channel_list\": {\"channel_name_1\": \"deneme\", \"channel_name_0\": \"Ev s\u0131cakl\u0131k takibi\", \"channel_id_0\": 136, \"channel_id_1\": 137}}"
I wanto to take channel_name_1 , channel_name_0 values.
Thanx to now
var veri;
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json' );
//headers.append('Authorization' , 'Basic '+ btoa(tok));
let options = new RequestOptions({ headers: headers });
let postParams = {
token: "381f13d7056-ce5fe474919",
user_id: "71",
}
var veris="channel_name_";
this.http.post("https://iothook.com/api/v1.0/channels/", postParams, options)
.subscribe(data => {
veri = data['_body'];
console.log(veri);
veri= veri.slice(1, -1);
veri = veri.replace(/\\/g, "");
veri = JSON.parse(veri);
for(var i = 0 ; i<2;i++)
{
veris+=i;
this.veriler.push({channelname: veri.channel.channel_name_1}); //THİS LİNE
console.log(veri.channel_name_1);
}
}, error => {
console.log(error);// Error getting the data
});
Upvotes: 0
Views: 41
Reputation: 5013
Im not sure what youre asking, but I think you want to use bracket notation, like this:
for(var i = 0; i < 2; i++){
veris += i;
this.veriler.push({ channelname: veri.channel['channel_name_' + (i + 1) }); //THİS LİNE
console.log(veri.channel['channel_name_' + (i + 1));
}
Upvotes: 1