2016-02-24, 20:05
hi all need to code python for afficher liste produit
this is code json
and this my code python for affiche
this is code json
Code:
[
{
"listProduit": [
{
"title": "Tom Yam Kung",
"descriptionProduit": "Soupe aux crevettes, champignons frais, citronnelle (piquant)",
"price": "39,00DHS",
"cat": "Soupes & Salades"
},
{
"title": "Tom Kha Kai",
"descriptionProduit": "Poulet, lait de coco, citronnelle",
"price": "35,00DHS",
"cat": "Soupes & Salades"
}
],
"nameCategory": "Soupes & Salades",
"imgCategory": "http://assets.hellofood.ma/dynamic/images/menucategories/13299_menu.jpg"
},
Code:
r = http.request('GET', 'http://localhost/category.json')
j=json.loads(r.data.decode("utf-8"))
mode = args.get('mode', None)
extra = args.get('extra',None)
if mode is None:
url = build_url({'mode': 'folder', 'extra': 'Restaurant'})
li = xbmcgui.ListItem('Restaurant', iconImage='DefaultFolder.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(addon_handle)
elif mode[0] == 'folder':
i=0
while i<len(j):
url = build_url({'mode': 'Category', 'extra': j[i]['listProduit']})
li = xbmcgui.ListItem(j[i]['nameCategory'], iconImage=j[i]['imgCategory'])
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,listitem=li, isFolder=True)
i=i+1
xbmcplugin.endOfDirectory(addon_handle)
this last party in erreur
elif mode[0] == 'Category':
i=0
while i<len(j):
url = build_url({'mode': 'Produit', 'extra': j[i]['listProduit']})
li = xbmcgui.ListItem(j[i]['listProduit']['title'])
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,listitem=li, isFolder=True)
i=i+1
xbmcplugin.endOfDirectory(addon_handle)