bjson

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

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

Go to latest
Published: Feb 6, 2017 License: Apache-2.0 Imports: 5 Imported by: 4

README

bjson

golang json util

show me the code

bjson_test.go

bs := []byte(`{"name":"bysir","sex":1,"age":21,"data":{"hab":"code"},"extra":["a",1]}`)
bj, _ := New(bs)

log.Print("ms: ", bj.MapString()) // map[extra: name:bysir sex:1 age:21 data:]
log.Print("mi: ",  bj.MapInterface()) //  map[name:bysir sex:1 age:21 data:map[hab:code] extra:[a 1]]
log.Printf("name: %s", bj.Pos("name").String()) // bysir
log.Printf("age: %d,%s", bj.Pos("age").Int(), bj.Pos("age").String()) // 21,21
log.Printf("sex: %t,%d", bj.Pos("sex").Bool(), bj.Pos("sex").Int()) // true,1
log.Printf("hab: %s", bj.Pos("data").Pos("hab").String()) // code
log.Printf("ext: len:%d data[0]:%s",bj.Pos("extra").Len(), bj.Pos("extra").Index(0).String()) // 2,a

log.Printf("E name: %d", bj.Pos("name").Int()) // 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bjson

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

use bjson.New to created it

func New

func New(data []byte) (*Bjson, error)

func (*Bjson) Bool

func (p *Bjson) Bool() bool

func (*Bjson) Float

func (p *Bjson) Float() float64

func (*Bjson) Index

func (p *Bjson) Index(index int) *Bjson

func (*Bjson) Int

func (p *Bjson) Int() int

func (*Bjson) Interface

func (p *Bjson) Interface() interface{}

func (*Bjson) IsArr

func (p *Bjson) IsArr() bool

func (*Bjson) IsNil

func (p *Bjson) IsNil() bool

func (*Bjson) IsObj

func (p *Bjson) IsObj() bool

func (*Bjson) Len

func (p *Bjson) Len() int

func (*Bjson) MapInterface

func (p *Bjson) MapInterface() map[string]interface{}

func (*Bjson) MapInterfaceSlilce

func (p *Bjson) MapInterfaceSlilce() []map[string]interface{}

func (*Bjson) MapString

func (p *Bjson) MapString() map[string]string

func (*Bjson) Object

func (p *Bjson) Object(v interface{}) error

func (*Bjson) Pos

func (p *Bjson) Pos(key string) *Bjson

func (*Bjson) String

func (p *Bjson) String() string

Jump to

Keyboard shortcuts

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