0

Here's code from the Riot Developer API.

I want to log the id from the body object in the console.

app.get('/hallo', function(req, res) {
var data = {};
var summoner = "dyrus";
var apikey = "xxxxxxxx";
var URL = "https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by- 
name/Teemo?api_key=" + apikey;
var URL2 = "https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by- 
name/" + summoner +"?api_key=" + apikey;

request(URL, function (err, data) {
  console.log(data.body);
 })
})

Writing:

console.log(data.body) 

Gives me back:

"{"id":34080052,"accountId":37712662,"name":"Teemo","profileIconId":0,"revisionDate":1495767212000,"summonerLevel":6}" 

How can I access the id field in the object body?

Adil B
  • 14,635
  • 11
  • 60
  • 78
Artjom
  • 1
  • 1

1 Answers1

0

you can access it this way:

JSON.parse(data.body).id

t3__rry
  • 2,817
  • 2
  • 23
  • 38