mjson

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndentJson

func IndentJson(data any) string

将任意 JSON-able 数据转换为缩进格式的 JSON 字符串。 错误时返回 "{}"。

func Marshal added in v0.3.1

func Marshal(v any) ([]byte, error)

将结构体转为 JSON 字节切片。

func PrintAny

func PrintAny(data any) string

打印任意 JSON-able 数据的缩进格式的 JSON 字符串,并返回该字符串。

func ReadyJsonFile added in v0.4.7

func ReadyJsonFile(filePath string, v any) (resErr error)

读取一个包含注释的 JSON 文件,去除注释后返回标准 JSON 格式的数据。 var result map[string]any err := ReadyJsonFile("demo.json", &result)

func StripComments added in v0.4.7

func StripComments(data []byte) ([]byte, error)

func ToByte

func ToByte(data any) ([]byte, error)

将任意数据转换为 JSON 字节切片。 JSON-able 包括结构体、map、切片等。 错误时返回非 nil 错误。

func ToMap

func ToMap(val any) (resData map[string]any, resErr error)

将任意 JSON-able 数据转换为 map[string]any。

func ToMapStr added in v0.1.4

func ToMapStr(val any) (resData map[string]string, resErr error)

将任意 JSON-able 数据转换为 map[string]string。

func ToStr

func ToStr(data any) string

将任意 JSON-able 数据转换为 JSON 字符串。 错误时返回 "{}"。

func Unmarshal added in v0.3.1

func Unmarshal(data []byte, v any) error

将 JSON 字节切片解析到结构体中。

func UnmarshalJsonc added in v0.4.7

func UnmarshalJsonc(data []byte, v any) error

解析带注释的 JSON 数据 var result map[string]any err := UnmarshalJsonc([]byte(str), &result)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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