Changeset 3714
- Timestamp:
- 08/01/08 06:41:26 (4 months ago)
- Files:
-
- trunk/projects/quickhoney/src/json.lisp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/projects/quickhoney/src/json.lisp
r3713 r3714 4 4 5 5 (defclass json-output-stream () 6 (( stream :readerstream7 :initarg :stream)6 ((output-stream :reader output-stream 7 :initarg :output-stream) 8 8 (stack :accessor stack 9 9 :initform nil))) … … 11 11 (defun next-aggregate-element () 12 12 (if (car (stack *json-output*)) 13 (princ (car (stack *json-output*)) ( stream *json-output*))13 (princ (car (stack *json-output*)) (output-stream *json-output*)) 14 14 (setf (car (stack *json-output*)) #\,))) 15 15 16 16 (defmacro with-json-output ((stream) &body body) 17 `(let ((*json-output* (make-instance 'json-output-stream : stream ,stream)))17 `(let ((*json-output* (make-instance 'json-output-stream :output-stream ,stream))) 18 18 ,@body)) 19 19 … … 27 27 (when (stack *json-output*) 28 28 (next-aggregate-element)) 29 (princ ,begin-char ( stream *json-output*))29 (princ ,begin-char (output-stream *json-output*)) 30 30 (push nil (stack *json-output*)) 31 31 (prog1 32 32 (progn ,@body) 33 33 (pop (stack *json-output*)) 34 (princ ,end-char ( stream *json-output*)))))34 (princ ,end-char (output-stream *json-output*))))) 35 35 36 36 (defmacro with-json-array (() &body body) … … 44 44 (defun encode-array-element (object) 45 45 (next-aggregate-element) 46 (json:encode-json object ( stream *json-output*)))46 (json:encode-json object (output-stream *json-output*))) 47 47 48 48 (defun encode-object-element (key value) 49 49 (next-aggregate-element) 50 (json:encode-json key ( stream *json-output*))51 (princ #\: ( stream *json-output*))52 (json:encode-json value ( stream *json-output*)))50 (json:encode-json key (output-stream *json-output*)) 51 (princ #\: (output-stream *json-output*)) 52 (json:encode-json value (output-stream *json-output*))) 53 53 54 54 (defmacro with-object-element ((key) &body body) 55 55 `(progn 56 56 (next-aggregate-element) 57 (json:encode-json ,key ( stream *json-output*))57 (json:encode-json ,key (output-stream *json-output*)) 58 58 (setf (car (stack *json-output*)) #\:) 59 59 (unwind-protect … … 63 63 (defmacro with-json-response (() &body body) 64 64 `(with-http-response (:content-type "application/json") 65 (with-json-output-to-string ()66 (with-json-object ()67 ,@body))))65 (with-json-output-to-string () 66 (with-json-object () 67 ,@body))))
