Ai
10 Star 25 Fork 6

@lisp CAD应用云/@lisp 函数库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
encode-from-alist.lsp 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
VitalGG 提交于 2022-11-02 23:59 +08:00 . json:encode-from-alist
(defun json:encode-from-alist (lst / lst2array )
"将关联列表转化为json串,测试版"
"list"
(defun lst2array (lst)
(strcat "["
(string:from-list
(mapcar '@:to-string lst)
",")
"]"))
(cond
((and (listp lst)
(not (null lst)))
(cond
((null (vl-list-length lst))
(strcat "{\"" (@:to-string (car lst))"\" : \""
(@:to-string (cdr lst)) "\"}")
)
((and (apply 'and (mapcar 'listp lst))
(apply 'and (mapcar '(lambda(x)(and (= 1 (length x))(atom (car x))))
lst)))
(lst2array (mapcar 'car lst)))
((= 1 (length lst))
(if (listp (car lst))
(json:encode-from-alist (car lst))
(@:to-string (car lst))))
((and (>= (length lst) 2)
(apply 'and (mapcar 'atom lst)))
(strcat "{\"" (@:to-string (car lst))"\" :"
(lst2array(cdr lst))"}"
))
(t
(strcat "{"
(string:from-list
(mapcar 'json:encode-from-alist lst)
",") "}"))
))
((atom lst)
(strcat " " (@:to-string lst)" ")
)))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Lisp
1
https://gitee.com/atlisp/atlisp-lib.git
git@gitee.com:atlisp/atlisp-lib.git
atlisp
atlisp-lib
@lisp 函数库
main

搜索帮助