json

package
v1.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package json 提供封装其他 json 序列化框架的接口。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(m MarshalFunc, u UnmarshalFunc)

Init 自定义 Marshal 和 Unmarshal 函数,为了防止在一个项目中存在多个 json 序列化框架,该函数只能在项目 main 函数执行前的 init 阶段设置一次。

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal 序列化 json 数据。

func MarshalIndent

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

MarshalIndent 序列化 json 数据并对结果进行美化。

func ToString

func ToString(i interface{}) string

ToString 将对象序列化为 Json 字符串,错误信息以字符串形式返回。

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal 反序列化 json 对象。

Types

type MarshalFunc

type MarshalFunc func(v interface{}) ([]byte, error)

MarshalFunc 定义 Marshal 函数原型。

type UnmarshalFunc

type UnmarshalFunc func(data []byte, v interface{}) error

UnmarshalFunc 定义 Unmarshal 函数原型。

Jump to

Keyboard shortcuts

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