Parse error while parsing json result - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33) +--- Forum: Supplementary Tools for Kodi (https://forum.kodi.tv/forumdisplay.php?fid=116) +--- Thread: Parse error while parsing json result (/showthread.php?tid=121264) |
Parse error while parsing json result - sebas - 2012-01-28 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 }, 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 Code: { 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. - Montellese - 2012-01-28 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. - sebas - 2012-01-28 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. - sebas - 2012-01-28 I've changed the jquery $.POST function to this and now it works Code: $.post('http://192.168.1.143:8080/jsonrpc', '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1}', The trick is to put the {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": 1} between ' '. - Montellese - 2012-01-28 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. RE: Parse error while parsing json result - steve55792 - 2014-05-03 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 ? |