encoding

package
v0.0.0-...-780ac92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrJSONNotValid 不是合法的json
	ErrJSONNotValid = errors.NewNoStackError("json is not valid")
)

Functions

This section is empty.

Types

type JSON

type JSON struct {
	// contains filtered or unexported fields
}

JSON json格式编码

func NewJSONFromBytes

func NewJSONFromBytes(b []byte) (*JSON, error)

NewJSONFromBytes 从字符流中b中获取JSON,该函数会检查格式合法性

func NewJSONFromFile

func NewJSONFromFile(filename string) (*JSON, error)

NewJSONFromFile 从文件filename中获取JSON,该函数会检查格式合法性

func NewJSONFromString

func NewJSONFromString(s string) (*JSON, error)

NewJSONFromString 从字符串s中获取JSON,该函数会检查格式合法性

func (*JSON) Clone

func (j *JSON) Clone() *JSON

Clone 克隆JSON

func (*JSON) Exists

func (j *JSON) Exists(path string) bool

Exists 判断path路径对应的值值是否存在,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) FromBytes

func (j *JSON) FromBytes(b []byte) error

FromBytes 将字节流b设置成JSON,会返回错误error

func (*JSON) FromFile

func (j *JSON) FromFile(filename string) error

FromFile 从文件名为filename的文件中读取JSON,会返回错误error

func (*JSON) FromString

func (j *JSON) FromString(s string) error

FromString 将字符串s设置成JSON,会返回错误error

func (*JSON) GetArray

func (j *JSON) GetArray(path string) ([]*JSON, error)

GetArray 获取path路径对应的值数组,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是数组或者不存在,就会返回错误

func (*JSON) GetBool

func (j *JSON) GetBool(path string) (bool, error)

GetBool 获取path路径对应的值bool值,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是bool值或者不存在,就会返回错误

func (*JSON) GetFloat64

func (j *JSON) GetFloat64(path string) (float64, error)

GetFloat64 获取path路径对应的值float64值,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是float64值或者不存在,就会返回错误

func (*JSON) GetInt64

func (j *JSON) GetInt64(path string) (int64, error)

GetInt64 获取path路径对应的值int64值,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是int64值或者不存在,就会返回错误

func (*JSON) GetJSON

func (j *JSON) GetJSON(path string) (*JSON, error)

GetJSON 获取path路径对应的值JOSN结构,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是json结构或者不存在,就会返回错误

func (*JSON) GetMap

func (j *JSON) GetMap(path string) (map[string]*JSON, error)

GetMap 获取path路径对应的值字符串映射,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是字符串映射或者不存在,就会返回错误

func (*JSON) GetString

func (j *JSON) GetString(path string) (string, error)

GetString 获取path路径对应的值String值,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c 如果path对应的不是String值或者不存在,就会返回错误

func (*JSON) IsArray

func (j *JSON) IsArray(path string) bool

IsArray 判断path路径对应的值是否是数组,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) IsBool

func (j *JSON) IsBool(path string) bool

IsBool 判断path路径对应的值是否是BOOL,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) IsJSON

func (j *JSON) IsJSON(path string) bool

IsJSON 判断path路径对应的值是否是JSON,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) IsNull

func (j *JSON) IsNull(path string) bool

IsNull 判断path路径对应的值值是否为空,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) IsNumber

func (j *JSON) IsNumber(path string) bool

IsNumber 判断path路径对应的值是否是数值,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) IsString

func (j *JSON) IsString(path string) bool

IsString 判断path路径对应的值是否是字符串,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) MarshalJSON

func (j *JSON) MarshalJSON() ([]byte, error)

MarshalJSON 序列化JSON

func (*JSON) Remove

func (j *JSON) Remove(path string) error

Remove 将path路径对应的值删除,会返回错误error,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) Set

func (j *JSON) Set(path string, v interface{}) error

Set 将path路径对应的值设置成v,会返回错误error,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) SetRawBytes

func (j *JSON) SetRawBytes(path string, b []byte) error

SetRawBytes 将path路径对应的值设置成b,会返回错误error,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) SetRawString

func (j *JSON) SetRawString(path string, s string) error

SetRawString 将path路径对应的值设置成s,会返回错误error,对于下列json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

要访问到x字符串 path每层的访问路径为a,a.b,a.b.0,a.b.0.c

func (*JSON) String

func (j *JSON) String() string

String 获取字符串表示

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL