richardvansoest

unread,
Mar 10, 2015, 9:58:34 AM3/10/15
to mitappinv...@googlegroups.com
Hello, i need to split the results from this json:

{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "season", "episode", "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 1 }, "id": "VideoGetItem"}

I would like to put the results in different labels like: Title, Duration,, Season (if any) etc.


Taifun

unread,
Mar 10, 2015, 10:37:03 AM3/10/15
to mitappinv...@googlegroups.com
use the JsonTextDecode block from the web component http://ai2.appinventor.mit.edu/reference/components/connectivity.html#Web

any JsonTextDecode(text jsonText)
Decodes the given JSON encoded value to produce a corresponding AppInventor value. A JSON list [x, y, z] decodes to a list (x y z), A JSON object with name A and value B, (denoted as A:B enclosed in curly braces) decodes to a list ((A B)), that is, a list containing the two-element list (A B).

see also

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

richardvansoest

unread,
Apr 1, 2015, 5:32:48 PM4/1/15
to mitappinv...@googlegroups.com
I get stuck on this:

first 2 are ok but index 3 has to become an index itself i think.

can someone help me here ?




json.png

Taifun

unread,
Apr 1, 2015, 5:57:15 PM4/1/15
to mitappinv...@googlegroups.com
use nested select list item blocks, see an example here

Taifun

unread,
Apr 1, 2015, 5:58:37 PM4/1/15
to mitappinv...@googlegroups.com
also you additionally might want to use the lookup in pairs block

richardvansoest

unread,
Apr 1, 2015, 6:12:33 PM4/1/15
to mitappinv...@googlegroups.com
i tried that already but stil get a lot of errors :(

How deep does the make list go ?

i understand the makelist > makelist etc

but not in combination to the json

i looked into the pairs to, but dont see how to use that with json either. 


Taifun

unread,
Apr 1, 2015, 6:52:28 PM4/1/15
to mitappinv...@googlegroups.com
How deep does the make list go ?
it can go very deep ... ;)
you should first learn how to work with lists and list of lists
i looked into the pairs to, but dont see how to use that with json either. 
if you have a list of lists, you can search for a key to get the corresponding value back

Taifun

richardvansoest

unread,
Apr 1, 2015, 8:40:49 PM4/1/15
to mitappinv...@googlegroups.com
efirst 2 working from id i get VideoGetItem and from jsonrpc i get 2.0, but after that comes: 

(result ((item ((album *empty-string*) (artist ()) (episode -1) (fanart *empty-string*) (file F:\Movies\Wild Card (2015)\QoQ-sbuSLN.462x.1.5DD.LD-BEW.p027.5102.draC.dliW.mkv) (label QoQ-sbuSLN.462x.1.5DD.LD-BEW.p027.5102.draC.dliW.mkv) (season -1) (showtitle *empty-string*) (streamdetails ((audio (((channels 6) (codec ac3) (language eng)))) (subtitle (((language dut)) ((language eng)))) (video (((aspect 2.41509) (codec h264) (duration 5539) (height 530) (stereomode *empty-string*) (width 1280)))))) (thumbnail *empty-string*) (title *empty-string*) (tvshowid -1) (type unknown))))))

i can filter result and get all the data after the space behind result.

I cant figure out how to get the data from that. tried item / (item / ((item  etc.....

do i have to split it first ?

Abraham Getzler

unread,
Apr 1, 2015, 11:24:33 PM4/1/15
to mitappinv...@googlegroups.com
I developed a little JSON browser utility to try to analyze RSS feeds.
It uses a stack and a ListView to show different levels and branches of
a JSON tree.

You have to paste your feed URL into the Block Editor,
in the global with URL in its name, and hit the Go button to
initiate the Web Get and the JSON parse, then 
navigate with the ListView and the Back buton.

I've attached screen shots,  block shots, and .aia source.

I notice two problems with it...

I only get 25 items per level.
I don't know if this is a limitation of the Web1.JSONDecode block or
my feed.

Also, my Back processing doesn't quite touch down properly
at the root of my stack.

It's usable, but not yet publication quality.

I hope you find it useful.

ABG

back.jpg
Screenshot 2015-04-01 23.07.44.png
showDepth.jpg
Web1_GotText.jpg
Back Button and Notifier.jpg
Designer.jpg
globals.jpg
Initialization.jpg
JSON_Feeds.aia
ListView1_AfterPicking.jpg
Screenshot 2015-04-01 23.05.10.png
Screenshot 2015-04-01 23.05.35.png
Screenshot 2015-04-01 23.06.32.png

richardvansoest

unread,
Apr 2, 2015, 7:31:13 AM4/2/15
to mitappinv...@googlegroups.com
Thanks Abraham, i am playing with it now to see if i can use some parts of it.

Taifun

unread,
Apr 2, 2015, 9:32:06 AM4/2/15
to mitappinv...@googlegroups.com
(result ((item ((album *empty-string*) (artist ()) (episode -1) (fanart *empty-string*) (file F:\Movies\Wild Card (2015)\QoQ-sbuSLN.462x.1.5DD.LD-BEW.p027.5102.draC.dliW.mkv) (label QoQ-sbuSLN.462x.1.5DD.LD-BEW.p027.5102.draC.dliW.mkv) (season -1) (showtitle *empty-string*) (streamdetails ((audio (((channels 6) (codec ac3) (language eng)))) (subtitle (((language dut)) ((language eng)))) (video (((aspect 2.41509) (codec h264) (duration 5539) (height 530) (stereomode *empty-string*) (width 1280)))))) (thumbnail *empty-string*) (title *empty-string*) (tvshowid -1) (type unknown))))))

first you have to select the inner list, which contains the tag/valaue pairs, I market it in red for you
in your case try


then you can use the lookup in pairs block
for example to get the value of the file tag, you would use this block

Taifun

richardvansoest

unread,
Apr 2, 2015, 4:23:43 PM4/2/15
to mitappinv...@googlegroups.com
I strugled all day with this. so i decided to make the program more rudimental for this problem.
Stil no real progres.
this is my whole program icl comment and error screen.
the json output depends on audio data or video data, on this image its video data from ncis episode.
(see comment)

What do i do wrong ?

 
Json_Decode.aia

Taifun

unread,
Apr 2, 2015, 4:31:28 PM4/2/15
to mitappinv...@googlegroups.com
you should use Do it to find out how kodi_player_data looks like
then you will realize, that you need 

select list item get global kodi_player_data
                      3 

instead of just get global kodi_player_data to get your pairs list, as you did in in your previous screenshot

edit:
listJson from my screenshot is your 
select list item get global kodi_player_data
                      3
hope that helps
the trick is to use Do it for each step ...

Taifun


Taifun

unread,
Apr 2, 2015, 4:37:50 PM4/2/15
to mitappinv...@googlegroups.com
actually a better solution to get the listJson from my screenshot is to do a 

lookup in pairs "result"
                      get global kodi_player_data
                      "not found"

Taifun                                                                               

richardvansoest

unread,
Apr 2, 2015, 5:26:56 PM4/2/15
to mitappinv...@googlegroups.com
Do i have to use diferent global pair names for every step ?
or can i use global pair for everey next item ??

richardvansoest

unread,
Apr 2, 2015, 6:16:30 PM4/2/15
to mitappinv...@googlegroups.com
I have made somthing that works..... pfffff dont know how exactly but it is getting me the date i need.

I think i do a lot wrong but now i have somthing i can try to make better, before i go further (for audio and normal movies)

any comments ?
Reply all
Reply to author
Forward
0 new messages