Elisp一天一函数(11)—— json-read-file

  • 函数名称:json-read-file
  • 函数原型:(json-read-file FILE)
  • 函数功能一句话描述:从一个文本文件中读取JSON结构数据,返回一个alist。
  • 函数用法demo:
    假设目前D盘有这样一个文件:D:/info.json,其内容如下:
{
  "name": "Tom",
  "age": 20,
  "score": {
    "English": 100,
    "Math": 85.5
  }
}

写下面的代码读取上面的文件:

(setq json-alist (json-read-file "d:/info.json"))
(print json-alist)
(print (alist-get 'name json-alist))
(print (alist-get 'Math (alist-get 'score json-alist)))

运行上面的代码,输出:

((name . "Tom") (age . 20) (score (English . 100) (Math . 85.5)))
"Tom"
85.5

猜你喜欢

转载自blog.csdn.net/weixin_34161029/article/details/87162852