这是来自Riot Developer API的代码。
我想从控制台中的body对象中记录id。
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);
})
})
写作:
console.log(data.body)
给我回复:
"{"id":34080052,"accountId":37712662,"name":"Teemo","profileIconId":0,"revisionDate":1495767212000,"summonerLevel":6}"
如何访问对象正文中的id
字段?
答案 0 :(得分:0)
你可以这样访问它:
JSON.parse(data.body).id