Kodi Community Forum

Full Version: parse json to xbmc list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
All recent versions of python have urllib2. What version are you running. Does the import urllib2 fail.
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