jamil egdemir <uncleja...@gmail.com> 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