skip to Main Content

JSON parse return error when found data != 0
i wrote a simple code to try, i had a server to request the data in JSON…
This is the error:
error

When the array are full of ‘0’ not appear the error.
i need to save the JSON objet in a const variable, and acces to the data later with "jsonVariable.someData[i]".

function pingMbServer() {
  const mbServer = new XMLHttpRequest();
  mbServer.timeout = 2000;
  mbServer.addEventListener("readystatechange", () => {
      const isDone = mbServer.readyState === 4;
      const isOk = mbServer.status === 200;
      mbServer.onload = function() {
        let arrayData = [];
        const datos = JSON.parse(this.responseText);
        arrayData = datos.almacen;
        alert("Length: "++datos.station.length);
        //...
      }
    }
  }

I try to search some info, but only found this:

Another important thing to keep in mind is that before JSON can be parsed it must first be stringified.

But i cant work with a string, i need to work with objets.
Something that i missed…?

2

Answers


  1. Chosen as BEST ANSWER

    How to delete this question... Because are not a real question... Its a mistake :-| Little embarrassing... (im new on this "blog/posts")


  2. Look closely at the response text.

    zoomed in

    The values under "almacen" aren’t ones (1) like you see in "station": they look like a lowercase L (l).

    Get whoever is creating the JSON data to create actual correct JSON.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search