Retrieve specific data from JSON Response

  Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
axlt2002 Offline
Fan
Posts: 403
Joined: Jun 2014
Reputation: 3
Location: Turin (Italy)
Post: #1
Hi guys,

I'm developing an add-on for the first time. The add-on is supposed to use JSON commands to obtain some information from the Kodi library as well as set/change some parameters in it.

I have actually a question related to how retrieve the IMDb id for a TV Show after having received the following JSON Response:

Code:
JSON Response: {"id":1,"jsonrpc":"2.0","result":{"limits":{"end":1,"start":0,"total":1},"tvshows":[{"label":"Stranger Things","mpaa":"TV-14","rating":9,"tvshowid":1,"uniqueid":{"imdb":"tt4574334","tmdb":"66732","tvdb":"305288"},"votes":"262868"}]}}

Basically, which is the code/syntax to save in a local variable (e.g. IMDb_id) the received tt4574334 value? I have tried the following code but the result in IMDb_id is None:

Code:
for item in jSonResponse['result']['tvshows']:
             IMDb_id = item.get('uniqueid[0]')

Thanks for any help...please take into account that I'm just facing JSON and python without any expereince on them... Rolleyes
find quote
axlt2002 Offline
Fan
Posts: 403
Joined: Jun 2014
Reputation: 3
Location: Turin (Italy)
Post: #2
Ok, after several trials, I found the way...at the end it was so obvious...

For who is interested:

Code:
for item in jSonResponse['result']['tvshows']:
             unique_id = item.get('uniqueid')
             imdb_id = unique_id.get('imdb')

The thread can be closed. Thanks.
find quote