Kodi Community Forum
parse json to xbmc list - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: parse json to xbmc list (/showthread.php?tid=157659)



parse json to xbmc list - smallpoul - 2013-02-26

Hi all,
i'm trying to make a plugin that will retrieval some data from a json. The main function of the plugin will be to control a vera box (home automation). All i want is to put all the device and scene in a list and be able to send url with id to control the vera. Vera have a json function and i'm able to pull information from python script. Here the simple code:
Code:
import urllib.request
import json

url = 'http://192.168.2.19:3480/data_request?id=sdata'
data = urllib.request.urlopen(url).read().decode("utf-8")
info = json.loads(data)
results = info['devices']

for r in results:
     print (r.get('id'))
     print (r.get('name'))
     print (r.get('status'))

With this code i'm able to print all the information that i want.
I will use the urllib2 function for the xbmc but in my python software, urllib2 is not installed.

Thanks and sorry for the newbie thing but it's been a while that i'm on it but without any success.


RE: parse json to xbmc list - Nuka1195 - 2013-02-26

All recent versions of python have urllib2. What version are you running. Does the import urllib2 fail.


parse json to xbmc list - smallpoul - 2013-02-26

Will take a look thanks. I use the urllib2 in the scripts. Some how when i test the code in python ide it give me an error. This does not give me problem. The problem is to parse json data to xbmc listing.
Thanks