dingjson

package module
v0.0.0-...-5484490 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: MIT Imports: 3 Imported by: 0

README

dingjson

go get -u github.com/dingdinglz/dingtools/dingjson

注意:无论是生成还是解析,你都需要通过NewFrom***来生成一个dingjson型的对象。通过操作该对象,可以完成生成,解析,转换等操作

生成一个json

type Test struct {
	Id   int    `json:"id"`
	What string `json:"what"`
}

json, err := NewFromStruct(&Test{
		Id:   1,
		What: "yyyy",
	})
	
json.ConventToStr()

解析一个json

json.GetInt()
json.GetString()
json.Get()
json.ArrayEach()
ArrayEach示例
type Test struct {
	Id   int    `json:"id"`
	What string `json:"what"`
}

type Test4 struct {
	What []Test `json:"what"`
}

json5, err := NewFromStruct(&Test4{What: []Test{
		{1, "2222"},
		{2, "3333"},
	}})
json5.ArrayEach(func(jsonin *DingJson) {
		logger.Info(jsonin.ConventToStr())
		logger.Info(jsonin.GetString("what"))
	}, "what")

调用一个api,解析json,下载图片的例子

随机p站图片下载

完整示例请查看json_test.go文件

详细文档

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

Version 返回dingjson的版本号

Types

type DingJson

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

func NewFromBytes

func NewFromBytes(src []byte) *DingJson

NewFromBytes 通过[]byte生成dingjson类型

func NewFromString

func NewFromString(str string) *DingJson

NewFromString 通过string生成dingjson类型

func NewFromStruct

func NewFromStruct(str interface{}) (*DingJson, error)

NewFromStruct 通过struct生成dingjson类型(推荐)

func (*DingJson) ArrayEach

func (d *DingJson) ArrayEach(eachFunc func(json *DingJson), keys ...string)

func (*DingJson) ConventToStr

func (d *DingJson) ConventToStr() string

ConventToStr 返回string的json

func (*DingJson) ConventToStruct

func (d *DingJson) ConventToStruct(v interface{}) error

ConventToStruct 将json对象转换为struct类型

func (*DingJson) Get

func (d *DingJson) Get(keys ...string) (*DingJson, error)

Get 取子json

func (*DingJson) GetInt

func (d *DingJson) GetInt(keys ...string) (int64, error)

GetInt 取-int

func (*DingJson) GetSrc

func (d *DingJson) GetSrc() []byte

GetSrc 返回[]byte类型的json

func (*DingJson) GetString

func (d *DingJson) GetString(keys ...string) (string, error)

GetString 取-string

Jump to

Keyboard shortcuts

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