[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trouble using hashq-get-handle in Guile
From: |
Mark H Weaver |
Subject: |
Re: Trouble using hashq-get-handle in Guile |
Date: |
Sun, 07 Dec 2014 19:38:52 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
jamil egdemir <address@hidden> writes:
> I'm having trouble getting the value associated with a key in a
> hash-table and I'm totally confused as to what I'm doing wrong. The
> code I'm using is shown below:
>
> (use-modules (curl))
> (use-modules (json))
>
> ;; use curl to hit the site's api to get results of query as json:
> (define handle (curl-easy-init))
> (curl-easy-setopt handle 'url
>
> "http://api.data.gov:80/regulations/v3/documents.json?api_key=mySecKey&countsOnly=0&encoded=1&dktid=EPA-HQ-OAR-2013-0602&dkt=R&cp=C&rpp=25&po=0";)
> (define s (curl-easy-perform handle))
>
> ;; parse the json in the string into guile scheme:
> (define queryResults (json-string->scm s))
>
> ;; use this to see the keys and values in the resulting hash
> table:
> (define print-hash (lambda (my-hash)
> (hash-for-each (lambda (key value)
> (format #t "~a => ~a~%" key value))
> my-hash)))
>
> ;; now let's take a look at the keys and values:
> (print-hash queryResults)
>
> ;; now let's get the value associated with the documents key:
> (hashq-get-handle queryResults 'documents)
Based on a quick glance at the json code, I suspect you want this:
(hash-get-handle queryResults "documents")
i.e. change 'hashq-get-handle' to 'hash-get-handle', and pass a string
as the key, not a symbol.
If you use "~s" instead of "~a" in 'print-hash', it will be clear
whether the keys are strings or symbols because strings will print
within double quotes.
Regards,
Mark