SyntaxError: Unexpected end of JSON input (I use link for get json information)

Hi, I want to get info in json api link.

var XMLHttpRequest = require(“xmlhttprequest”).XMLHttpRequest;
const Http = new XMLHttpRequest();
const url2=‘http://mcapi.us/server/status?ip=’ + ‘185.216.25.56’ + ‘&port=’ + 25565;
Http.open(“GET”, url2);
Http.send();
Http.onreadystatechange = (e) => {
const obj = JSON.parse(Http.responseText);
console.log(obj.players.max);
console.log(obj.players.now);

}

Hey, Xenors,

all right ? so, we do not understand if this error refers to your bot, or IF it is an error, or what exactly do you want, if it is in case you want to know about the API, follow below, please Thank me if I have you helped.

{"status":"error","online":false,"motd":"","error":"missing data","players":{"max":0,"now":0},"server":{"name":"","protocol":0},"last_online":"","last_updated":"","duration":0}

how to thank me ( pls, do this ):

  • In the Project Editor, clicking on their avatar and selecting ‘Thank for Helping’.
  • The button will update and say ‘Thanked’ when your thanks has been logged.

In your server, this is infos in the api:

Click on this: http://mcapi.us/server/status?ip=185.216.25.56 link

I try to make live version I need the bot go in the after the player execute the command and check the information in the json api

Hey @Xenors,

Can you try using the Fetch API to get info from the JSON API link:

const url2 = 'http://mcapi.us/server/status?ip=' + '185.216.25.56' + '&port=' + 25565;

fetch(url2)
  .then(res => res.json())
  .then(obj => {
    console.log(obj.players.max);
    console.log(obj.players.now);
   });

Can you try this and let me know if it doesn’t work?

1 Like

thx work !!! ;3

I help you, link from you Glitch Discord Bot, and authorize me to help.

@erickzildox, @Xenors’s problem has already been solved (SyntaxError: Unexpected end of JSON input (I use link for get json information)).