[racket] How to parse json from a web API
Suppose you have
(define L .. the quoted list below ..)
and
;; Symbol Any -> Void
;; add key and value to the GUI
(define (send-to-gui key value)
... )
Then you can do things like this:
> (for ((h (in-list L))) (for (([key value] h)) (send-to-gui key value)))
The outer for loop iterates over list L and binds each of the hashes to h. The inner for loop iterates over the key-value pairs in each hash h. It binds each such pair, separately, to the variables key and value. The body of the inner loop can do what it wants. I used send-to-gui here. You may wish to see what displayln does.
-- Matthias
On Jun 8, 2014, at 10:02 AM, Kieran Coldron wrote:
> This is my first time using racket or any lisp like language, but so far I really like racket but I'm a complete noob.
>
> I am wanting to make a simple application in racket for the website hummingbird.me, an anime tracking website. Here is a mockup of the gui in racket.
> <gwelbo.png>
>
>
> I want to populate this list-box with the json data from the users libary
>
> this is what the json data looks like http://pastebin.com/VXNnZGbk and after converting it to a hash:
>
> '(#hasheq((private . #f)
> (id . 5419481)
> (status . "currently-watching")
> (episodes_watched . 12)
> (last_watched . "2014-06-07T22:49:04.788Z")
> (rewatched_times . 0)
> (notes . null)
> (notes_present . null)
> (rewatching . #f)
> (anime .
> #hasheq(
> (url . "http://hummingbird.me/anime/baccano")
> (title . "Baccano!")
> (status . "Finished Airing")
> (slug . "baccano")
> (alternate_title . "")
> (episode_count . 13)
> (cover_image . "http://static.hummingbird.me/anime/poster_images/000/002/039/large/26DCC78BD23438E7D713B8E2A825F46F_800_1094.jpg?1383481747")
> (synopsis . "")
> (show_type . "TV")))
> (rating . #hasheq(
> (value . "4.5")
> (type . "advanced"))))
> #hasheq((private . #f)
> (id . 5419483)
> (status . "currently-watching")
> (episodes_watched . 12)
> (last_watched . "2014-06-07T22:49:22.644Z")
> (rewatched_times . 0)
> (notes . null)
> (notes_present . null)
> (rewatching . #f)
> (anime .
> #hasheq(
> (url . "http://hummingbird.me/anime/steins-gate")
> (title . "Steins;Gate")
> (status . "Finished Airing")
> (slug . "steins-gate")
> (alternate_title . "")
> (episode_count . 24)
> (cover_image . "http://static.hummingbird.me/anime/poster_images/000/005/646/large/5646.jpg?1387138585")
> (synopsis . "")
> (show_type . "TV")))
> (rating . #hasheq(
> (value . "5.0")
> (type . "advanced")))))
>
> I understand that somehow I have to loop through the the hash to get the data I require and possibly store it in a second hash? How would I go about doing this?
> Sorry if this is a stupid question and having no idea what I'm doing.
>
> --
> Kieran Coldron
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140608/4419bebf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4463 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140608/4419bebf/attachment.p7s>