ZGG文档
  • 语言特性
    • ZGG简介
    • 开始使用ZGG
    • 在Go程序中嵌入ZGG脚本
  • ZGG基本语法
    • ZGG的变量
    • ZGG内置类型-字符串
    • ZGG内置类型-数组
    • ZGG的函数
    • 条件判断
      • if语句
      • switch语句
      • 三目运算符
      • when表达式
    • 循环控制
  • 标准库
    • 内置标准库
      • base64 -- TODO
      • concurrent -- TODO
      • cron -- TODO
      • db -- TODO
      • dbop -- TODO
      • dom -- TODO
      • file -- TODO
      • go -- TODO
      • http
      • json
      • kv -- TODO
      • msgpack -- TODO
      • nsq -- TODO
      • ptable -- TODO
      • random
      • redis -- TODO
      • regexp -- TODO
      • sh -- TODO
      • sys -- TODO
      • template -- TODO
      • time
      • url -- TODO
由 GitBook 提供支持
在本页
  • 函数目录
  • 函数详解
  • func encode(value, indent?)
  • func decode(strOrBytes)
  • func format(strOrBytes, indent?)
  • func find(jsonpath, value)
  1. 标准库
  2. 内置标准库

json

上一页http下一页random

最后更新于2年前

json提供了JSON操作相关的函数

函数目录

函数详解

func encode(value, indent?)

将value序列化为json字符串,返回Str

indent如果不缺省,序列化结果会带上换行和缩进,以更可读的形式生成。其中:

  • 当indent为Int时:每一个层级前面加上层级数乘以indent个空格作为缩进

  • 当indent为Str时:每一个层架前面加上层级数乘以indent字符串作为缩进

func decode(strOrBytes)

解析json字符串,返回解析出来的zgg value,是encode的逆操作

func format(strOrBytes, indent?)

将json字符串以指定形式重新格式化(以提高可读性)。format(a, b)实际上是encode(decode(a), b)的简化形式

func find(jsonpath, value)

通过jsonpath,获取value的指定字段内容

注:当传入value类型为Str或者Bytes时,find函数会先对value进行json.decode操作,即

s := '{"a":1}'
//以下两行是等价的
@json.find('$.a', s)
@json.find('$.a', @json.decode(s))

具体jsonpath的语法,请参考

github.com/oliveagle/jsonpath
func encode()
func decode()
func format()
func find()