@toasters

Как отправлять несколько значений из JSON?

vk.updates.hear(/^(?:4)$/i, async (context) => { 
    axios.get(`https://minecraft-statistic.net/api/server/top/145.239.133.118_25565/all/1`).then(res => {
		return res.data;
    }).then(data => {
		let place = data.data[0].place || 0
        let nickname = data.data[0].nickname || 0
		return context.send(`${place}/${nickname}`);
	})
	});

{"server_id":182507,"page":1,"data":[{"nickname":"Waidelos","place":1,"time":45390,"last_visit":1553199600},{"nickname":"5opka","place":2,"time":34100,"last_visit":1553224805},{"nickname":"Abashev","place":3,"time":32400,"last_visit":1553281814},{"nickname":"K_i_t_n_e_s_s","place":4,"time":31480,"last_visit":1553233206},{"nickname":"mafiozznik","place":5,"time":27600,"last_visit":1553284815},{"nickname":"_kirl","place":6,"time":24830,"last_visit":1553289615},{"nickname":"Estol","place":7,"time":24340,"last_visit":1553291416},{"nickname":"MrBrison","place":8,"time":23520,"last_visit":1553267412},{"nickname":"Nataxa_Ts","place":9,"time":21970,"last_visit":1553188199},{"nickname":"_Sofiya_Star","place":10,"time":21250,"last_visit":1553104785},{"nickname":"Gerda_Svir","place":11,"time":20880,"last_visit":1551641748},{"nickname":"_MRavent_","place":12,"time":19880,"last_visit":1553272213},{"nickname":"_H3R0_","place":13,"time":19390,"last_visit":1553114987},{"nickname":"Vermaks","place":14,"time":19320,"last_visit":1551575737},{"nickname":"Seryoga_Ts","place":15,"time":17760,"last_visit":1553278814},{"nickname":"ZZEFIRKA","place":16,"time":17150,"last_visit":1553290816},{"nickname":"Panti1337_","place":17,"time":16330,"last_visit":1549061817},{"nickname":"bigblackspider","place":18,"time":16300,"last_visit":1553272213},{"nickname":"CMETAHOCKA","place":19,"time":15460,"last_visit":1551929795},{"nickname":"LemKrem","place":20,"time":15390,"last_visit":1549190838},{"nickname":"Goos1k","place":21,"time":14860,"last_visit":1552786133},{"nickname":"_LakiYT_","place":22,"time":14650,"last_visit":1553289015},{"nickname":"Angel4mo","place":23,"time":13920,"last_visit":1548096859},{"nickname":"Malino4ka_","place":24,"time":13840,"last_visit":1553104185},{"nickname":"KaneGIII","place":25,"time":13730,"last_visit":1553183398},{"nickname":"GiuseppeYT","place":26,"time":13700,"last_visit":1544010187},{"nickname":"rJlaBa","place":27,"time":13190,"last_visit":1552774731},{"nickname":"_GRIZLI_","place":28,"time":13150,"last_visit":1553116187},{"nickname":"igroman1","place":29,"time":13150,"last_visit":1553229005},{"nickname":"retroFM4ik","place":30,"time":13110,"last_visit":1552999168}],"status_query":"ok"}


Сейчас получаю только 1 значение nickname и place, но надо получать все значения и отправлять их.

0EW-fQalnbk.jpg
  • Вопрос задан
  • 323 просмотра
Решения вопроса 1
@egorlisss
vk.updates.hear(/^(?:4)$/i, async (context) => { 
    axios.get(`https://minecraft-statistic.net/api/server/top/145.239.133.118_25565/all/1`).then(res => {
		return res.data;
    }).then(data => {
		let message = ''; 
    data.data.forEach(item => {
		data.data.sort((a, b) => a.place - b.place);
		message += item.nickname + ' - Место ' + item.place + '\n';
    })
	return context.send(message);
	})
	});
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы