Documentation
¶
Overview ¶
Package rawjson provides the raw bytes json.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // The capacity size of the buffer. BufCapSize = 512 // If true, compact the raw bytes json。 Compact = true )
Functions ¶
This section is empty.
Types ¶
type Bytes ¶
type Bytes []byte
Bytes represent a raw byte json.
Example ¶
/// Empty
fmt.Println("\nEmpty")
bs, _ := Bytes(nil).MarshalJSON()
fmt.Printf("1: [%s]\n", string(bs))
bs, _ = Bytes("").MarshalJSON()
fmt.Printf("2: [%s]\n", string(bs))
buf := bytes.NewBuffer(nil)
Bytes(nil).WriteTo(buf)
fmt.Printf("3: [%s]\n", buf.String())
buf.Reset()
Bytes(nil).WriteTo(buf)
fmt.Printf("4: [%s]\n", buf.String())
/// No Compact
fmt.Println("\nNo Compact")
Compact = false
bs, _ = Bytes(` {"a" : 123 , "b" : " a b c "} `).MarshalJSON()
fmt.Printf("5: [%s]\n", string(bs))
/// Compact
fmt.Println("\nCompact")
Compact = true
bs, _ = Bytes(` {"a" : 123 , "b" : " a b c "} `).MarshalJSON()
fmt.Printf("6: [%s]\n", string(bs))
bs, _ = Bytes(` 123 `).MarshalJSON()
fmt.Printf("7: [%s]\n", string(bs))
bs, _ = Bytes(` " 123 " `).MarshalJSON()
fmt.Printf("8: [%s]\n", string(bs))
Output: Empty 1: [""] 2: [""] 3: [""] 4: [""] No Compact 5: [ {"a" : 123 , "b" : " a b c "} ] Compact 6: [{"a":123,"b":" a b c "}] 7: [123] 8: [" 123 "]
func (Bytes) MarshalJSON ¶
MarshalJSON implements the interface json.Marshaler.
If Compact is true, compact the bytes. If the bytes is empty, return []byte(`""`) instead.
func (Bytes) MarshalText ¶
MarshalText implements the interface encoding.TextMarshaler, which is equal to bs.MarshalJSON().
Click to show internal directories.
Click to hide internal directories.