Parse error while parsing json result
#1
Question 
I'm having a problem parsing the json result from XBMC using javascript/jquery.

I use the following code to get a list of movies from my xbmc media library:
Code:
$.post('http://192.168.1.143:8080/jsonrpc', { "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {  }, "id": 1 },
        function(data){
        
            var movies = JSON.stringify(data);
            $("#log").append("Data: <br />" + movies)
            
         }, "json");
At the moment I only want to put the json result in a <div> with the id: log.

What I get as a result in the log div is this:
{"error":{"code":-32700,"message":"Parse error."},"id":0,"jsonrpc":"2.0"}

When I send the data: { "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { }, "id": 1 } to XBMC using the Simple REST client for Google Chrome I get a response from XBMC with a json encoded list of all the movies in my library.

According to Wikipedia error 32700 indicates that invalid Json is returned. However the result I get in the REST client looks valid to me.

The result I get using the REST client is:
Headers:
Code:
Date: Sat, 28 Jan 2012 09:37:55 GMT
Content-Length: 29047
Content-Type: application/json
Data (snippet):
Code:
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "end" : 105,
      "movies" : [
         {
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/ffffffff.tbn",
            "file" : "videodb://1/7/4/",
            "label" : "James Bond Collection"
         },
         {
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/ffffffff.tbn",
            "file" : "videodb://1/7/5/",
            "label" : "Pirates of the Caribbean Collection"
         },
         {
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/ffffffff.tbn",
            "file" : "videodb://1/7/6/",
            "label" : "BBC Earth Yellowstone"
         },
         {
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/1df148d9.tbn",
            "file" : "//desktop/films/Bride Wars [2009]/VIDEO_TS/VIDEO_TS.IFO",
            "label" : "Bride Wars",
            "movieid" : 1,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/1/1df148d9.tbn"
         },

I'm stuck on what's causing the parse error. Is it the response from XBMC or am I sending the wrong data to XBMC? I hope some of you are able to point me in the right direction.
Reply
#2
The parse error comes from XBMC telling you that your request is not valid JSON(-RPC). I took a quick look at your data and it looks valid to me but I never used jQuery before so I don't know if it works the way you use it. The default webinterface uses jQuery to IIRC so you might wanna take a look at how it's done there. Maybe you'll have to provide the JSON-RPC request as a string i.e. putting single quotes ' around your request.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#3
Montellese Wrote:The parse error comes from XBMC telling you that your request is not valid JSON(-RPC). I took a quick look at your data and it looks valid to me but I never used jQuery before so I don't know if it works the way you use it. The default webinterface uses jQuery to IIRC so you might wanna take a look at how it's done there. Maybe you'll have to provide the JSON-RPC request as a string i.e. putting single quotes ' around your request.

Changing the " to ' didn't help. I tried creating a javascript object instead of posting the string using $.parseJSON() but that didn't help either.

The webinterfaces I've looked at so far either use the old http api or send the json request in the same way as I do.
Reply
#4
I've changed the jquery $.POST function to this and now it works Laugh
Code:
    $.post('http://192.168.1.143:8080/jsonrpc', '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1}',
            function(data){
            
                var movies = JSON.stringify(data);
                $("#log").append("Data: <br />" + movies);
                
             }, "json");

The trick is to put the {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} between ' '.
Reply
#5
That's what I meant with surrounding the request with single quotes ;-) I didn't mean that you replace the " with ' because JSON requires double quotes for property names and strings.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#6
put the {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} between ' '. where in xbmc mylibrary

put the {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} between ' '. where in xbmc mylibrary ?
Reply

Logout Mark Read Team Forum Stats Members Help
Parse error while parsing json result0