代码拉取完成,页面将自动刷新
(defun json:parse (str)
"Json 字符串转化为 lisp 列表。"
"list"
(setq lst-str (vl-string->list str))
(setq flag-escape nil)
(setq flag-quote nil)
(setq flag-keylevel 0)
(setq flag-arraylevel 0)
(setq atom-str-lst '())
;;(setq res nil)
(while lst-str
(setq curr-char (car lst-str))
(cond
((= (ascii "\\") curr-char)
(setq flag-escape (not flag-escape))
(setq atom-str-lst (cons curr-char atom-str-lst))
)
((and (= (ascii "\"") curr-char)
(null flag-escape))
(setq flag-escape nil)
(setq flag-quote (not flag-quote))
(setq atom-str-lst (cons curr-char atom-str-lst))
)
(t
(setq flag-escape nil)
(if flag-quote
(setq atom-str-lst (cons curr-char atom-str-lst))
(cond
((= (ascii "{") curr-char)
;;对象 key/value mode
(setq flag-keylevel (1+ flag-keylevel))
(setq atom-str-lst (cons (ascii "(") atom-str-lst))
)
((= (ascii "[") curr-char)
;;array mode
(setq flag-arraylevel (1+ flag-arraylevel))
(if(= pre-char (ascii ":"))
(setq atom-str-lst (cons (ascii "(") (cdddr atom-str-lst)))
(setq atom-str-lst (cons (ascii "(") atom-str-lst)))
)
((= (ascii "}") curr-char)
;;对象 key/value mode
(setq flag-keylevel (1- flag-keylevel))
(setq atom-str-lst (cons (ascii ")") atom-str-lst))
)
((= (ascii "]") curr-char)
;;array mode
(setq flag-arraylevel (1- flag-arraylevel))
(setq atom-str-lst (cons (ascii ")") atom-str-lst)))
((= (ascii ":") curr-char)
;; 处理 key
(setq atom-str-lst
(cons (ascii " ")
(cons (ascii ".")
(cons (ascii " ") atom-str-lst))))
)
((= (ascii ",")curr-char)
;; value
(setq atom-str-lst
(cons (ascii "(")
(cons (ascii ")")
atom-str-lst)))
)
(t (setq atom-str-lst (cons curr-char atom-str-lst)))
))))
(setq pre-char curr-char)
(setq lst-str(cdr lst-str))
)
(read(strcat "(" (vl-list->string (reverse atom-str-lst)) ")"))
)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。