Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/JSON/Emacs-Lisp/json-1.l
Normal file
18
Task/JSON/Emacs-Lisp/json-1.l
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(require 'cl-lib)
|
||||
|
||||
(cl-assert (fboundp 'json-parse-string))
|
||||
(cl-assert (fboundp 'json-serialize))
|
||||
|
||||
(defvar example "{\"foo\": \"bar\", \"baz\": [1, 2, 3]}")
|
||||
(defvar example-object '((foo . "bar") (baz . [1 2 3])))
|
||||
|
||||
;; decoding
|
||||
(json-parse-string example) ;=> #s(hash-table [...]))
|
||||
;; using json.el-style options
|
||||
(json-parse-string example :object-type 'alist :null-object nil :false-object :json-false)
|
||||
;;=> ((foo . "bar") (baz . [1 2 3]))
|
||||
;; using plists for objects
|
||||
(json-parse-string example :object-type 'plist) ;=> (:foo "bar" :baz [1 2 3])
|
||||
|
||||
;; encoding
|
||||
(json-serialize example-object) ;=> "{\"foo\":\"bar\",\"baz\":[1,2,3]}"
|
||||
19
Task/JSON/Emacs-Lisp/json-2.l
Normal file
19
Task/JSON/Emacs-Lisp/json-2.l
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(require 'json)
|
||||
|
||||
(defvar example "{\"foo\": \"bar\", \"baz\": [1, 2, 3]}")
|
||||
(defvar example-object '((foo . "bar") (baz . [1 2 3])))
|
||||
|
||||
;; decoding
|
||||
(json-read-from-string example) ;=> ((foo . "bar") (baz . [1 2 3]))
|
||||
;; using plists for objects
|
||||
(let ((json-object-type 'plist))
|
||||
(json-read-from-string)) ;=> (:foo "bar" :baz [1 2 3])
|
||||
;; using hash tables for objects
|
||||
(let ((json-object-type 'hash-table))
|
||||
(json-read-from-string example)) ;=> #<hash-table equal 2/65 0x1563c39805fb>
|
||||
|
||||
;; encoding
|
||||
(json-encode example-object) ;=> "{\"foo\":\"bar\",\"baz\":[1,2,3]}"
|
||||
;; pretty-printing
|
||||
(let ((json-encoding-pretty-print t))
|
||||
(message "%s" (json-encode example-object)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue