Documentation ¶
Index ¶
- Variables
- func AddModifier(name string, fn func(json, arg string) string)
- func ForEachLine(json string, iterator func(line Result) bool)
- func ModifierExists(name string, fn func(json, arg string) string) bool
- func Valid(json string) bool
- func ValidBytes(json []byte) bool
- type Query
- type Result
- func (t Result) Array() []Result
- func (t Result) Bool() bool
- func (t Result) Exists() bool
- func (t Result) Float() float64
- func (t Result) ForEach(iterator func(key, value Result) bool)
- func (t Result) Get(path string) Result
- func (t Result) Int() int64
- func (t Result) IsArray() bool
- func (t Result) IsObject() bool
- func (t Result) Less(token Result, caseSensitive bool) bool
- func (t Result) Map() map[string]Result
- func (t Result) Path(json string) string
- func (t Result) Paths(json string) []string
- func (t Result) String() string
- func (t Result) Time() time.Time
- func (t Result) Uint() uint64
- func (t Result) Value() interface{}
- type Type
Constants ¶
This section is empty.
Variables ¶
View Source
var DisableModifiers = false
DisableModifiers will disable the modifier syntax
Functions ¶
func AddModifier ¶
AddModifier 将一个自定义修饰符命令绑定到GJSON语法。 这个操作不是线程安全的,应该在使用所有其他查询函数之前执行。
func ForEachLine ¶
ForEachLine 通过JSON lines指定的JSON行进行迭代
func ModifierExists ¶
ModifierExists 当指定的修饰符存在时返回true。
Types ¶
type Result ¶
type Result struct { Type Type // json类型 Raw string // 格式化的json Str string // 字符串的json Num float64 // json数字 Index int // 对于原始json中的原始值,0表示索引未知 Indexes []int // 在包含“#”查询字符的路径上匹配的所有元素。 }
Result 表示从Get()返回的json值。
func GetManyBytes ¶
GetManyBytes 在json中搜索多个路径 返回值是一个Result数组,其中项的数量将等于输入路径的数量。
func Parse ¶
Parse 解析json并返回一个结果。 这个函数期望json是格式良好的,并且不进行验证。 无效的json将不会异常,但它可能返回意想不到的结果。 如果您使用的JSON来自一个不可预测的来源,那么您可能希望首先使用Valid函数。
func ParseBytes ¶
ParseBytes 解析json并返回一个结果。如果使用字节,此方法优于Parse(string(data))
func (Result) Exists ¶
Exists 如果值存在,返回true。
if query.Get(json, "name.last").Exists(){ println("value exists") }
func (Result) ForEach ¶
ForEach 遍历每个值 如果结果表示不存在的值,则不会迭代任何值。 如果结果是Object,迭代器将传递每个项的键和值。如果结果是Array,迭代器将只传递每一项的值。 如果结果不是JSON数组或对象,迭代器将返回一个等于结果的值。
func (Result) Less ¶
Less 如果一个令牌小于另一个令牌,则返回true。 当令牌为string时,使用caseSensitive参数。比较两种不同类型时的顺序为:
Null < False < Number < String < True < JSON
Click to show internal directories.
Click to hide internal directories.