How to read results from a JSONRPC Call
#1
I have the following line of code that returns a sting of all my movies an rating. I need to then create a loop that goes through the resulting movies can anyone help?

json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "mpaa"]}, "id": 1}')

FOR {each movie} IN {json_query}:
commands

Thanks.
Reply
#2
Example:
https://github.com/XBMC-Addons/script.ar...loader#L67
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
Thanks Martijn, That got me much farther but I seem to be having an issue with a movie title Here is my code and error message


self.__log('Using JSON for retrieving MOVIE info')
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["file", "title", "year", "trailer", "streamdetails"], "sort": { "method": "label" } }, "id": 1}')
json_response = unicode(json_response, 'utf-8', errors='ignore')
jsonobject = simplejson.loads(json_response)
if jsonobject['result'].has_key('movies'):
for item in jsonobject['result']['movies']:
self.__log('Movie id=%s %s' %( item.get('title',''), item.get('file','') ) )


When it hits my Alien3 movie i get the error

08:10:49 T:2643700544 ERROR: Error Type: <type 'exceptions.UnicodeEncodeError'>
08:10:49 T:2643700544 ERROR: Error Contents: 'ascii' codec can't encode character u'\xb3' in position 38: ordinal not in range(128)

Any thoughts? Thanks again.
Reply
#4
The log message can't decode the Alien3 (that special character) in the name.
I had the same. So i did some weird py-fu coding to fix that

https://github.com/XBMC-Addons/script.ar...ils.py#L59
(the part before that line handles the special characters)
This can probably be done a lot simpler but it works Smile
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#5
Thanks, I will give that a try and see.

Reply
#6
(2012-06-07, 16:16)DoubleD_1980 Wrote: Thanks, I will give that a try and see.

So.only printing to the log fails. You can use the unaltered title in python itself without problems
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#7
That fixed the logging, Thanks for your help
Reply

Logout Mark Read Team Forum Stats Members Help
How to read results from a JSONRPC Call0