-1

I would to navigate inside json to parsing json'data'. I tried to use JSON Stringfy but nothing. Another i would to navigate inside data to parse 'hometeam' for example. Thank you for your eventually help

var TelegramBot = require ('node-telegram-bot-api');
var token = '********';
var bot = new TelegramBot(token, {polling:true});
var request = require('request');
const { parse } = require('path');

bot.on("polling_error", (err) => console.log(err));
bot.onText(/\/start/, function(msg, match) {

        var chatId = msg.chat.id;
    request('https://www.oddsmath.com/api/v1/dropping-odds.json/?language=en&timezone=Europe%2FRome&provider_id=32&country_code=IT&cat_id=0&interval=60&sortBy=1&time=24&limit=20', function(error,response,body){
       if(!error && response.statusCode == 200){
           bot.sendMessage(chatId, 'Looking for...', {parse_mode:'Markdown'})
           .then(function(msg){
               var res = JSON.parse(body);
               var dat = res.data;

               console.log(dat);
               bot.sendMessage(chatId, 'Result:\n' + dat)
           })

       }
    });
});

The JSON I am parsing looks like this

{
  "3207031-0": {
    "time": '2020-06-16 12:30:00',
    "hometeam": "Regar-TadAZ Tursunzoda",     
    "awayteam": "FK Istiklol",     
    "league": "Tajikistan - National Football League"
  },
  {...}
}
5
  • Hey @phil its unclear what you want to achieve.Will you please rephrase the question? Commented Jun 16, 2020 at 11:07
  • Data from res.data seems to have proper json structure. What is your question? If you want to loop trough that response try to use Object.keys(dat) Commented Jun 16, 2020 at 11:10
  • Hi @Supercool. I want for example get hometeam text from first element of res.data Commented Jun 16, 2020 at 11:17
  • Are you able to see log in your console @phil? If please add the response to the question Commented Jun 16, 2020 at 11:31
  • This is log, but not is all @Supercool { '3207031-0': { time: '2020-06-16 12:30:00', hometeam: 'Regar-TadAZ Tursunzoda', awayteam: 'FK Istiklol', league: 'Tajikistan - National Football League', Commented Jun 16, 2020 at 11:51

1 Answer 1

1

To access the hometext value of first entry inside res.data

Try something like this

const hometeam = Object.values(res.data)[0].hometeam

let res = {
  data: {
    '3207031-0': {
      time: '2020-06-16 12:30:00',
      hometeam: 'Regar-TadAZ Tursunzoda',
      awayteam: 'FK Istiklol',
      league: 'Tajikistan - National Football League'
    }
  }
}
const hometeam=Object.values(res.data)[0].hometeam
console.log(hometeam)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.