Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 4 of 4
  1. #1

    JSON response can't be parsed as XML

    LMS 8.1.0 - Trying to parse JSON respons with JavaScript. Firefox Console report
    "XML Parsing Error: not well-formed"
    I've tried to force response to (text/xml) and even manually loaded the responseText into DOMParser() with the same error.

    Wonder if other have similar problem with the JSON repsonse? And possible workaround?

    request:
    Code:
    {"id":1,"method":"slim.request","params":["00:04:20:26:2a:25",["status","-",1,"tags:aulyB"]]}
    response:
    Code:
    {"result":{"digital_volume_control":0,"seq_no":"47","player_connected":1,"can_seek":1,"playlist_cur_index":"5","rate":1,"playlist_timestamp":1611020450.26858,"playlist mode":"off","mode":"stop","playlist_tracks":19,"power":1,"player_name":"Stue Touch","playlist repeat":0,"time":0,"mixer volume":100,"playlist shuffle":0,"player_ip":"192.168.10.51:46056","playlist_loop":[{"artist":"PolyGram","year":"0","id":94136,"album":"1998 - Reklame Klassikere","title":"I Just Want to Make Love to You - Etta Jones","playlist index":5,"url":"file:///srv/dev-disk-by-label-Musikk-HDD/4GBs/wav/Diverse/PolyGram/1998%20-%20Reklame%20Klassikere/06%20-%20I%20Just%20Want%20to%20Make%20Love%20to%20You%20-%20Etta%20Jones.wav"}],"signalstrength":0,"duration":222},"method":"slim.request","params":["00:04:20:26:2a:25",["status","-",1,"tags:aulyB"]],"id":1}

    Actual Javascript formated request string used for POST:
    Code:
    var request = "{\"id\":1,\"method\":\"slim.request\",\"params\":[\"00:04:20:26:2a:25\",[\"status\",\"-\",1,\"tags:aulyB\"]]}";

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,932
    However, it is JSON not XML ... so why is it trying to parse as XML?
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

  3. #3
    duh... what I feel now are not suitable for print.

    I got lost in my way thought w3schools documentation. Thanks for setting me straight. w3schools do actually have a whole chapter on the differences.

    Make sure NOT to use overrideMimeType("text/xml") then use JSON.parse(this.responseText) silenced the Console error detection.

  4. #4
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    3,932
    Easily happens.

    I spent a few minutes yesterday trying to work out why some JavaScript wasn't working ... and in the end spotted that I it was the only line in that chunk of code with a semi-colon at the end ... I then remembered that this particular application is not in JavaScript but in VBScript.
    Paul Webster
    http://dabdig.blogspot.com
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, Supla Finland, ABC Australia, CBC/Radio-Canada and RTE Ireland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •