json

package
v1.0.14 Latest Latest
Warning

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

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

README

自定义json类型

一些带有特殊用途的类型

json string

json 字符串

使用场景:

import "gitee.com/novanest/toolkit/util/json"

var str = json.Val(`{"demo": true, "num": 123}`)

data := struct {
  S Val
}{str}

json.Marshal(data) // {"S":{"demo":true,"num":123}}

data2 := struct{
  Demo bool
  Num int
}{}
str.JSON(&data2) // 也可以直接 json 反序列化

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonMap

type JsonMap map[string]interface{}

JSONObj json 对象, 序列化的时候,变成纯字符串

func (JsonMap) JSON

func (m JsonMap) JSON(v interface{}) error

func (JsonMap) String

func (m JsonMap) String() Val

type Time

type Time time.Time

Time 时间别名,在json序列化的时候,会格式成 2006-01-02 15:04:05 这种时间格式 结合 gorm 使用,存在数据库的是时间类型,转到接口的是上述时间格式

func (Time) MarshalJSON

func (tm Time) MarshalJSON() ([]byte, error)

type Val

type Val string

Val json 字符串

func (Val) JSON

func (s Val) JSON(v interface{}) error

func (Val) MarshalJSON

func (s Val) MarshalJSON() ([]byte, error)

MarshalJSON 格式化为json字符串的时候,会格式化成 object

Jump to

Keyboard shortcuts

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