On this page:
gen:  To  JSON
To  JSON?
->json
json->string
json->byte
3.8.1 JSON扩展方法
json/  ->primitive
json/  read
8.12

3.8 JSON🔗

提供稍微便利的json操作写法。

转成json的接口,需最小实现->json

procedure

(ToJSON? a)  boolean?

  a : any/c
是否实现了gen:ToJSON

procedure

(->json a)  jsexpr?

  a : gen:ToJSON
将可转的数据,转成jsexpr?

procedure

(json->string a)  string?

  a : gen:ToJSON
a转化成string?

Examples:
> (json->string "hello")

"\"hello\""

> (json->string 1)

"1"

> (json->string (list 1 (list "hello") "world"))

"[1,[\"hello\"],\"world\"]"

procedure

(json->byte a)  bytes?

  a : gen:ToJSON
a转化成bytes?

Examples:
> (json->byte "hello")

#"\"hello\""

> (json->byte (list 1 (list "hello") "world"))

#"[1,[\"hello\"],\"world\"]"

3.8.1 JSON扩展方法🔗

procedure

(json/->primitive value)  any/c

  value : jsexpr?
将JSON转化为原始类型数据。

Examples:
> (json/->primitive (list 1 2 3))

(Array 1 2 3)

> (json/->primitive 'null)

(Nothing)

> (json/->primitive (hash 'a (list 1 2 3) 'b (hash 'name 2 'age 4)))

(Map '(b . #<Map: (name . 2) (age . 4)>) '(a . #<Array: 1 2 3>))

procedure

(json/read port)  any/c

  port : input-port?
input-port?中读取出json。