Closed azzamsa closed 5 years ago
Working with API response that din't have have square brackets is a breeze. It's the elisp equivalent generated by request.el for wayback API.
((url . "https://c3lt.de/35c3/talk/BRKHHG/")
(archived_snapshots))
{
"url": "https://c3lt.de/35c3/talk/BRKHHG/",
"archived_snapshots": {}
}
((url . https://www\.nytimes\.com/2019/02/10/opinion/dan-savage-jeff-bezos-national-enquirer\.html)
(archived_snapshots
(closest
(status . 200)
(available . t)
(url . http://web\.archive\.org/web/20190211001619/https://www\.nytimes\.com/2019/02/10/opinion/dan-savage-jeff-bezos-national-enquirer\.html)
(timestamp . 20190211001619))))
{
"url": "https://www.nytimes.com/2019/02/10/opinion/dan-savage-jeff-bezos-national-enquirer.html",
"archived_snapshots": {
"closest": {
"status": "200",
"available": true,
"url": "http://web.archive.org/web/20190211073027/https://www.nytimes.com/2019/02/10/opinion/dan-savage-jeff-bezos-national-enquirer.html",
"timestamp": "20190211073027"
}
}
}
Anyone had idea how to work with response that wrapped with []
square brackets ?
Turn out if JSON response inside []
(an array of object in Javascript), json-read-file
will parse it as vector
. I have hard time solving this, before I've an idea to see it's type. Now since it's a vector I can get the value using elt
.
ELISP> (setq ghub-response (json-read-file "github.json"))
[((id . "44445566")
(unread . t)
(reason . "mention")
(updated_at . "2019-02-11T10:41:23Z")
(last_read_at . "2019-02-10T16:27:56Z")....
ELISP> (type-of ghub-response)
vector <----- it was vector
ELISP> (nth 0 ghub-response)
*** Eval error *** Wrong type argument: listp, [((id . "435345677")
(unread . t)... <----- failed to use list operation
ELISP> (elt ghub-response 0)
((id . "43511")
(unread . t)
(reason . "mention")
(updated_at . "2019-02-11T10:41:23Z")
(last_read_at . "2019-02-10T16:27:56Z") <----- works using vector operation
this library help me build my first Emacs package. But now, I am stuck with an error "Wrong type argument: listp".
I try to maka a GET request with the following code
The JSON response is
I save the response to
ghub-response
variable. then the error comes upWhy request can't parse the json response to equivalent elisp data structure correctly ? I think maybe the response contains
[]
square brackets.Thanks for request.