Documentation ¶
Overview ¶
Package json_tool...
Description : 动态构建json
Author : go_developer@163.com<白茶清欢>
Date : 2021-03-10 10:26 下午
Package json_tool ...
Description : 将复杂数据结构转化为 JSONNode 树
Author : go_developer@163.com<白茶清欢>
Date : 2021-03-14 10:40 下午
Package json_tool ...
Description : json_tool ...
Author : go_developer@163.com<张德满>
Date : 2022/01/22 9:19 PM
Package json_tool ...
Description : json_tool ...
Author : go_developer@163.com<张德满>
Date : 2022-01-09 10:48 PM
Index ¶
- Constants
- func GetDataType(value gjson.Result) string
- func GetJSONDataStruct(data string) ([]string, error)
- type DataFilter
- type DynamicJSON
- func (dj *DynamicJSON) Map() (map[string]interface{}, error)
- func (dj *DynamicJSON) ParseWithReceiver(receiver interface{}) error
- func (dj *DynamicJSON) SetValue(path string, value interface{}, isComplexType bool)
- func (dj *DynamicJSON) Slice() ([]interface{}, error)
- func (dj *DynamicJSON) String() string
- type Field
- type Filter
- type FilterDataRule
- type FilterOption
- type JSONode
- type MapDataRule
Constants ¶
const ( // FieldTypeInt ... FieldTypeInt = "int64" // FieldTypeIntSlice ... FieldTypeIntSlice = "[]int64" // FieldTypeFloat ... FieldTypeFloat = "float64" // FieldTypeFloatSlice ... FieldTypeFloatSlice = "[]float64" // FieldTypeBool ... FieldTypeBool = "bool" // FieldTypeBoolSlice ... FieldTypeBoolSlice = "[]bool" // FieldTypeString ... FieldTypeString = "string" // FieldTypeStringSLice ... FieldTypeStringSLice = "string" // FieldTypeAny ... FieldTypeAny = "interface{}" // FieldTypeAnySlice ... FieldTypeAnySlice = "[]interface{}" // FieldTypeSlice ... FieldTypeSlice = "[]interface{}" // FieldTypeMap ... FieldTypeMap = "map" // FieldTypeMapSlice ... FieldTypeMapSlice = "[]map" )
const (
// PathSplit json_tool 路径的分割符
PathSplit = "."
)
Variables ¶
This section is empty.
Functions ¶
func GetJSONDataStruct ¶
GetJSONDataStruct 获取JSON数据的结构
Author : go_developer@163.com<张德满>
Date : 10:53 PM 2022/1/9
Types ¶
type DataFilter ¶
type DataFilter struct {
// contains filtered or unexported fields
}
DataFilter 数据过滤
Author : go_developer@163.com<白茶清欢>
Date : 2022/1/22 9:20 PM
func NewDataFilter ¶
func NewDataFilter(source string, filterRule []*FilterDataRule, filterOption *FilterOption) *DataFilter
NewDataFilter 获取数据过滤方法实例
Author : go_developer@163.com<白茶清欢>
Date : 2022/1/22 9:50 PM
func (*DataFilter) Filter ¶
func (df *DataFilter) Filter() (string, error)
Filter 数据过滤
Author : go_developer@163.com<白茶清欢>
Date : 2022/1/22 9:36 PM
type DynamicJSON ¶
type DynamicJSON struct {
// contains filtered or unexported fields
}
DynamicJSON 动态json
Author : go_developer@163.com<白茶清欢>
Date : 11:03 下午 2021/3/10
func NewDynamicJSON ¶
func NewDynamicJSON() *DynamicJSON
NewDynamicJSON 获取JSON实例
Author : go_developer@163.com<白茶清欢>
Date : 10:36 下午 2021/3/10
func (*DynamicJSON) Map ¶
func (dj *DynamicJSON) Map() (map[string]interface{}, error)
Map 转化为map
Author : go_developer@163.com<白茶清欢>
Date : 9:59 上午 2021/9/9
func (*DynamicJSON) ParseWithReceiver ¶
func (dj *DynamicJSON) ParseWithReceiver(receiver interface{}) error
ParseWithReceiver 使用指定结构解析
Author : go_developer@163.com<白茶清欢>
Date : 10:01 上午 2021/9/9
func (*DynamicJSON) SetValue ¶
func (dj *DynamicJSON) SetValue(path string, value interface{}, isComplexType bool)
SetValue 设置节点值,如果节点不存在,创建;如果已存在,更新, 多级key使用, value 必须是基础数据类型, 如果是结构体, 需要继续添加path,多级path使用.分割
Author : go_developer@163.com<白茶清欢>
Date : 10:45 下午 2021/3/10
func (*DynamicJSON) Slice ¶
func (dj *DynamicJSON) Slice() ([]interface{}, error)
Slice 转化为slice
Author : go_developer@163.com<白茶清欢>
Date : 9:59 上午 2021/9/9
func (*DynamicJSON) String ¶
func (dj *DynamicJSON) String() string
String 获取字符串的格式JSON
Author : go_developer@163.com<白茶清欢>
Date : 2:16 下午 2021/3/11
type Field ¶
type Field struct { Path string `json:"path"` // 路径 Type string `json:"type"` // 类型 Example string `json:"example"` // 示例值 }
Field ...
Author : go_developer@163.com<张德满>
Date : 2022/1/10 10:47 PM
func GetJSONDataStructWithType ¶
GetJSONDataStructWithType 获取数据结构,并获取类型
Author : go_developer@163.com<张德满>
Date : 2022/1/10 10:47 PM
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter 解析json树
Author : go_developer@163.com<白茶清欢>
Date : 10:41 下午 2021/3/14
func NewFilter ¶
func NewFilter(data interface{}, rule map[string]MapDataRule) *Filter
NewFilter 获取解析的实例
Author : go_developer@163.com<白茶清欢>
Date : 10:43 下午 2021/3/14
func (*Filter) Result ¶
func (f *Filter) Result() (*DynamicJSON, error)
Result 数据过滤结果
Author : go_developer@163.com<白茶清欢>
Date : 10:44 下午 2021/3/14
type FilterDataRule ¶
type FilterDataRule struct { SourceKey string // 原始数据路径 MapKey string // 提取后映射到的数据路径 DefaultValue interface{} // 原始数据路径不存在时的默认值 WithDefault bool // 是否使用默认值 }
FilterDataRule 参数过滤规则
Author : go_developer@163.com<白茶清欢>
Date : 2022/1/22 9:44 PM
type JSONode ¶
type JSONode struct { Key string // json_tool key Value interface{} // 对应的值 Child []*JSONode // 子节点 IsRoot bool // 是否根节点 IsHasLastBrother bool // 在此之后是否有其他兄弟节点 IsSlice bool // 是否是list IsIndexNode bool // 是否是slice的索引节点 Sort int // 此属性用于 slice解析,保证最终排序是对的 IsComplex bool // 是否为复杂数据类型 IsString bool // 是否为字符串 }
JSONode JSOM节点
Author : go_developer@163.com<白茶清欢>
Date : 10:33 下午 2021/3/10