简体   繁体   中英

Javascript not reading json file

I am making html tag based player, which needs playlist to play. I have problems reading json file (local file) on chromium on Raspberry Pi 3. Whole thing already works on my laptop with EDGE (getJSON works on Raspberry later in the code). The error I get is statusText: parser error.

I already tried ajax and all combos like: reading text and then parsing it to json object, I played around with ajax parameters (tried jsonp as well). Its funny that the same function works without any problems 10s into the code. Also both json files were checked by validator and are okay.

Btw I have a python script that runs all of that in chromium with --allow-all-files...

//All variables are defined as var globally

//READ PLAYLIST
//This is the function that returns error (it is called by body -> onload)

  function read_playlist() {
    $.getJSON("playlist.json", function (data) {
      music = data;
      cnt = data.length;
    });    
  }


//READ SLIDESHOW
//This is the same function without error (is called by setTimeout(this, 1000))

  $.getJSON("./slideshow.json", function (data1) {
    imgs = data1;
    i_cnt = data1.length;
    i_index = data1.length;
  });

And here is json saved as playlist.json

[{"title":"George Ezra - Paradise","download":"music\/2018 Weekly Charts\/George Ezra - Paradise.mp3","file":"songs\/George Ezra - Paradise.mp3","poster":"images\/logo.png","mp3":"songs\/George Ezra - Paradise.mp3"},{"title":"Jax Jones - Breathe (feat. Ina Wroldsen)_N","download":"music\/2018 Weekly Charts\/Jax Jones - Breathe (feat. Ina Wroldsen)_N.mp3","file":"songs\/Jax Jones - Breathe (feat. Ina Wroldsen)_N.mp3","poster":"images\/logo.png","mp3":"songs\/Jax Jones - Breathe (feat. Ina Wroldsen)_N.mp3"}]

and slideshow.json

["logo.png", "l.jpg"]

Okay so the problem was not in the script but in json. I posted json from my laptop which was downloaded from same link that the raspberry has downloaded it. But that python file somehow turns json "hm" to 'hm' so it isn't valid anymore (since 'hm' is not a string).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM