In a related thread https://emacs.stackexchange.com/a/34336/2287, a string (containing JSON data) is converted using json-read-from-string
. The value returned in that example looks like this:
((1 . [((id . 2)
(attribute . salutation)
(displayName . Salutation)
(category . 1))
((id . 4)
(attribute . middlename)
(displayName . Middle Name)
(category . 1))
((id . 6)
(attribute . suffix)
(displayName . Suffix)
(category . 1))
((id . 8)
(attribute . city)
(displayName . City)
(category . 1))
((id . 9)
(attribute . state)
(displayName . State)
(category . 1))
((id . 11)
(attribute . email)
(displayName . Email)
(category . 1))
((id . 12)
(attribute . telephone)
(displayName . Telephone)
(category . 1))
((id . 10)
(attribute . zipCode)
(displayName . Zip Code)
(category . 1))
((id . 13)
(attribute . telephoneExtension)
(displayName . Telephone Extension)
(category . 1))
((id . 7)
(attribute . streetAddress)
(displayName . Street Address)
(category . 1))
((id . 3)
(attribute . firstName)
(displayName . First Name)
(category . 1))
((id . 1)
(attribute . fullName)
(displayName . Full Name)
(category . 1))
((id . 5)
(attribute . lastName)
(displayName . Last Name)
(category . 1))
((id . 14)
(attribute . notes)
(displayName . Notes)
(category . 1))])
(2 . [((id . 15)
(attribute . name)
(displayName . Name)
(category . 2))
((id . 16)
(attribute . address)
(displayName . Address)
(category . 2))
((id . 17)
(attribute . phone)
(displayName . Phone)
(category . 2))
((id . 18)
(attribute . email)
(displayName . email)
(category . 2))
((id . 19)
(attribute . url)
(displayName . URL)
(category . 2))])
(3 . [((id . 20)
(attribute . name)
(displayName . Name)
(category . 3))
((id . 21)
(attribute . address)
(displayName . address)
(category . 3))
((id . 22)
(attribute . county)
(displayName . County)
(category . 3))
((id . 23)
(attribute . state)
(displayName . State)
(category . 3))
((id . 24)
(attribute . zipcode)
(displayName . Zip Code)
(category . 3))
((id . 25)
(attribute . pin)
(displayName . PIN)
(category . 3))
((id . 26)
(attribute . longitude)
(displayName . Longitude)
(category . 3))
((id . 27)
(attribute . latitude)
(displayName . Latitude)
(category . 3))]))
Evaluating the above-mentioned return value with (assoc '\1 ...)
produces a cell, the car
of which is a symbol whose name is the string "1"
. The O.P. in that related thread (like myself) experiences difficulty printing the symbol using message
[(void-function \,)
], and in the comments a solution to accomplish that objective is to use setq
: (setq id '\1)
.
I would like to convert the symbol 1
to a number without using a global variable. I have tried storing that symbol as a let-bound variable and then attempted to change it with setq
, however, this does not work (presumably because the variable is only let-bound).
EDIT: To include a minimal working example below:
EXAMPLE:
(let* ((string
"{
\"access_token\" : \"1234\",
\"scope\" : \"PlaceTrades AccountAccess MoveMoney\",
\"expires_in\" : 1800,
\"token_type\" : \"Bearer\"
}")
(json (progn (require 'json)
(json-read-from-string string)))
(token-type (cdr (assq 'token_type json)))
(expires-in (cdr (assq 'expires_in json)))
(scope (cdr (assq 'scope json)))
(access-token (cdr (assq 'access_token json))))
(message "token-type: %s\nexpires-in: %s\nscope: %s\naccess-token: %s"
token-type, expires_in, scope, access-token)
access-token)
DEBUGGER:
Debugger entered--Lisp error: (void-function \,)
,expires_in
(message "token-type: %s\nexpires-in: %s\nscope: %s\naccess-tok..." token-type ,expires_in ,scope ,access-token)
(let* ((string "{\n \"access_token\" : \"1234\",\n \"scope\" : \"PlaceTra...") (json (progn (require 'json) (json-read-from-string string))) (token-type (cdr (assq 'token_type json))) (expires-in (cdr (assq 'expires_in json))) (scope (cdr (assq 'scope json))) (access-token (cdr (assq 'access_token json)))) (message "token-type: %s\nexpires-in: %s\nscope: %s\naccess-tok..." token-type ,expires_in ,scope ,access-token) access-token)
(progn (let* ((string "{\n \"access_token\" : \"1234\",\n \"scope\" : \"PlaceTra...") (json (progn (require 'json) (json-read-from-string string))) (token-type (cdr (assq 'token_type json))) (expires-in (cdr (assq 'expires_in json))) (scope (cdr (assq 'scope json))) (access-token (cdr (assq 'access_token json)))) (message "token-type: %s\nexpires-in: %s\nscope: %s\naccess-tok..." token-type ,expires_in ,scope ,access-token) access-token))
eval((progn (let* ((string "{\n \"access_token\" : \"1234\",\n \"scope\" : \"PlaceTra...") (json (progn (require 'json) (json-read-from-string string))) (token-type (cdr (assq 'token_type json))) (expires-in (cdr (assq 'expires_in json))) (scope (cdr (assq 'scope json))) (access-token (cdr (assq 'access_token json)))) (message "token-type: %s\nexpires-in: %s\nscope: %s\naccess-tok..." token-type ,expires_in ,scope ,access-token) access-token)) t)
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)