Documentation ¶
Overview ¶
json 组件封装,基于encoding/json
Index ¶
- Variables
- func Marshal(v interface{}, nullTag, boolTag string) ([]byte, error)
- func Unmarshal(jsonByte []byte, v interface{}) error
- func ValidateArray(jsonArray interface{}, validDatas []interface{}) bool
- func ValidateMap(jsonMap interface{}, validData map[string]interface{}) bool
- type DataType
- type DataTypeNotnil
- type Json
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // json data type // TypeInt = DataType(1) TODO golang json parse no int type TypeFloat = DataType(2) TypeBool = DataType(3) TypeString = DataType(4) TypeArray = DataType(5) TypeMap = DataType(6) // json not nil data type TypeNotnilFloat = DataTypeNotnil(2) TypeNotnilBool = DataTypeNotnil(3) TypeNotnilString = DataTypeNotnil(4) TypeNotnilArray = DataTypeNotnil(5) TypeNotnilMap = DataTypeNotnil(6) )
Functions ¶
func Marshal ¶
*
- parse json bytes data *
- @param `v` handle object struct or map or slice
- @param `nullTag` nil tag, field or data is nil replace
- e.g.:
- default "" - 如果空字符串不会将(空数据)字段或key添加到json解析的数据中
- "null" - 空数据解析: {"Key":null}
- "nil" - 空数据解析: {"Key":nil}
- @param `boolTag` bool tag
- e.g.:
- default "" - {"KeyBool":trye|false}
- "YES|NO" - {"KeyBool":YES|NO}
- "1|0" - {"KeyBool":1|0}
- @return []byte
- @return error
func Unmarshal ¶
*
- json bytes to struct or slice or map *
- @param `jsonByte`
- @param `v` pointer object
func ValidateArray ¶
func ValidateArray(jsonArray interface{}, validDatas []interface{}) bool
*
- validate array type data
- can nesting validate *
- `validData` :
- [
- TypeInt,
- TypeNotnilString,
- map[string]interface{}{
- childField1: TypeNotnilString
- childField2: TypeFloat
- },
- []interface{}{
- TypeString,
- TypeInt,
- TypeNotnilString
- }
- ] *
- @param `jsonArray` json array struct
- @param `validData` valid data validate
- @return valid data is true
func ValidateMap ¶
*
- validate map type data
- can nesting validate *
- `validData` :
- {
- Field1:TypeInt,
- Field2:TypeNotnilString,
- Field3:map[string]interface{}{
- childField1: TypeNotnilString
- childField2: TypeFloat
- },
- Field4:[]interface{}{
- TypeString,
- TypeInt,
- TypeNotnilString
- }
- } *
- @param `jsonMap` json map struct
- @param `validData` valid data validate
- @return valid data is true
Types ¶
type DataType ¶
type DataType int8
*
- json struct data type *
- value type is int|float|string|array|map
type Json ¶
type Json struct {
// contains filtered or unexported fields
}
*
- Json struct object
func NewJson ¶
*
- parse interface data new Json object *
- @param `v` handle object struct or map or slice
- @param `nullTag` nil tag, field or data is nil replace
- e.g.:
- default "" - 如果空字符串不会将(空数据)字段或key添加到json解析的数据中
- "null" - 空数据解析: {"Key":null}
- "nil" - 空数据解析: {"Key":nil}
- @param `boolTag` bool tag
- e.g.:
- default "" - {"KeyBool":trye|false}
- "YES|NO" - {"KeyBool":YES|NO}
- "1|0" - {"KeyBool":1|0}
- @return Json
- @return error
func NewJsonNil ¶
*
- new nil Json struct object *
- @param isArray YES nil info = [], NO nil info = {} *
Click to show internal directories.
Click to hide internal directories.