xjson

package
v0.20.15 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: Apache-2.0 Imports: 1 Imported by: 5

README

GoKit - xjson

Json kits for Golang development.

Installation

go get -u github.com/likexian/gokit

Importing

import (
    "github.com/likexian/gokit/xjson"
)

Documentation

Visit the docs on GoDoc

Visit simplejson docs on GoDoc

Example

Dump the struct data to JSON string
// Define Status struct
type Status struct {
    Code    int64  `json:"code"`
    Message string `json:"message"`
}

// Init status
status := Status{1, "Success"}

// Encode as json string
s, err := xjson.Encode(status)
if err == nil {
    fmt.Println("Json text is:", s)
}
Load the JSON string
// Json strig
text := `{"Code": 1, "Message": "Success", "Result": {"Student": [{"Name": "Li Kexian"}]}}`

// Decode json string
j, err := xjson.Decode(text)
if err == nil {
    fmt.Println("Code is:", j.Get("Code").MustInt(0))
    fmt.Println("Message is:", j.Get("Message").MustString(""))
    fmt.Println("First Student name is:", j.Get("Result.Student.0.Name").MustString("-"))
}

LICENSE

Copyright 2012-2019 Li Kexian

Licensed under the Apache License 2.0

About

DONATE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Author

func Author() string

Author returns package author

func Dump

func Dump(f string, v interface{}) error

Dump dump value to json file

func Encode

func Encode(v interface{}) (string, error)

Encode encode value to json text

func License

func License() string

License returns package license

func Version

func Version() string

Version returns package version

Types

type Jsonx

type Jsonx struct {
	*simplejson.Json
}

Jsonx is the json object

func Decode

func Decode(s string) (*Jsonx, error)

Decode decode json string to Json object

func Load

func Load(f string) (*Jsonx, error)

Load load json file to Json object

Jump to

Keyboard shortcuts

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