如何访问类-json从JSON解码的对象?
How to access object decoded from JSON by cl-json?
我正在尝试在 Common Lisp 中导入 JSON。我想出了如何从 JSON 字符串解码对象,但我不知道如何访问返回的对象的属性。要解码字符串(并将结果存储在 ***tempjson** 中),我这样做:
(defun test-json ()
(with-input-from-string
(s "{\"foo\": [1, 2, 3], \"bar\": true, \"baz\": \"!\"}")
(defparameter *tempjson* (json:decode-json s))))
如何访问 *tempjson* 数据。例如,如何获取 foo 属性?
的值
decode-json
出现在 return 关联列表中(至少在这种情况下;参见 documentation). You can access the values with the function assoc
:
(defun test-json ()
(with-input-from-string (s "{\"foo\": [1, 2, 3], \"bar\": true, \"baz\": \"!\"}")
(let ((data (json:decode-json s)))
(format t "~a~%" (rest (assoc :foo data))))))
我正在尝试在 Common Lisp 中导入 JSON。我想出了如何从 JSON 字符串解码对象,但我不知道如何访问返回的对象的属性。要解码字符串(并将结果存储在 ***tempjson** 中),我这样做:
(defun test-json ()
(with-input-from-string
(s "{\"foo\": [1, 2, 3], \"bar\": true, \"baz\": \"!\"}")
(defparameter *tempjson* (json:decode-json s))))
如何访问 *tempjson* 数据。例如,如何获取 foo 属性?
的值decode-json
出现在 return 关联列表中(至少在这种情况下;参见 documentation). You can access the values with the function assoc
:
(defun test-json ()
(with-input-from-string (s "{\"foo\": [1, 2, 3], \"bar\": true, \"baz\": \"!\"}")
(let ((data (json:decode-json s)))
(format t "~a~%" (rest (assoc :foo data))))))