Source File
handy.go
Belonging Package
github.com/valyala/fastjson
package fastjson
var handyPool ParserPool
// GetString returns string value for the field identified by keys path
// in JSON data.
//
// Array indexes may be represented as decimal numbers in keys.
//
// An empty string is returned on error. Use Parser for proper error handling.
//
// Parser is faster for obtaining multiple fields from JSON.
func ( []byte, ...string) string {
:= handyPool.Get()
, := .ParseBytes()
if != nil {
handyPool.Put()
return ""
}
:= .GetStringBytes(...)
:= string()
handyPool.Put()
return
}
// GetBytes returns string value for the field identified by keys path
// in JSON data.
//
// Array indexes may be represented as decimal numbers in keys.
//
// nil is returned on error. Use Parser for proper error handling.
//
// Parser is faster for obtaining multiple fields from JSON.
func ( []byte, ...string) []byte {
:= handyPool.Get()
, := .ParseBytes()
if != nil {
handyPool.Put()
return nil
}
:= .GetStringBytes(...)
// Make a copy of sb, since sb belongs to p.
var []byte
if != nil {
= append(, ...)
}
handyPool.Put()
return
}
// GetInt returns int value for the field identified by keys path
// in JSON data.
//
// Array indexes may be represented as decimal numbers in keys.
//
// 0 is returned on error. Use Parser for proper error handling.
//
// Parser is faster for obtaining multiple fields from JSON.
func ( []byte, ...string) int {
:= handyPool.Get()
, := .ParseBytes()
if != nil {
handyPool.Put()
return 0
}
:= .GetInt(...)
handyPool.Put()
return
}
// GetFloat64 returns float64 value for the field identified by keys path
// in JSON data.
//
// Array indexes may be represented as decimal numbers in keys.
//
// 0 is returned on error. Use Parser for proper error handling.
//
// Parser is faster for obtaining multiple fields from JSON.
func ( []byte, ...string) float64 {
:= handyPool.Get()
, := .ParseBytes()
if != nil {
handyPool.Put()
return 0
}
:= .GetFloat64(...)
handyPool.Put()
return
}
// GetBool returns boolean value for the field identified by keys path
// in JSON data.
//
// Array indexes may be represented as decimal numbers in keys.
//
// False is returned on error. Use Parser for proper error handling.
//
// Parser is faster for obtaining multiple fields from JSON.
func ( []byte, ...string) bool {
:= handyPool.Get()
, := .ParseBytes()
if != nil {
handyPool.Put()
return false
}
:= .GetBool(...)
handyPool.Put()
return
}
// Exists returns true if the field identified by keys path exists in JSON data.
//
// Array indexes may be represented as decimal numbers in keys.
//
// False is returned on error. Use Parser for proper error handling.
//
// Parser is faster when multiple fields must be checked in the JSON.
func ( []byte, ...string) bool {
:= handyPool.Get()
, := .ParseBytes()
if != nil {
handyPool.Put()
return false
}
:= .Exists(...)
handyPool.Put()
return
}
// Parse parses json string s.
//
// The function is slower than the Parser.Parse for re-used Parser.
func ( string) (*Value, error) {
var Parser
return .Parse()
}
// MustParse parses json string s.
//
// The function panics if s cannot be parsed.
// The function is slower than the Parser.Parse for re-used Parser.
func ( string) *Value {
, := Parse()
if != nil {
panic()
}
return
}
// ParseBytes parses b containing json.
//
// The function is slower than the Parser.ParseBytes for re-used Parser.
func ( []byte) (*Value, error) {
var Parser
return .ParseBytes()
}
// MustParseBytes parses b containing json.
//
// The function panics if b cannot be parsed.
// The function is slower than the Parser.ParseBytes for re-used Parser.
func ( []byte) *Value {
, := ParseBytes()
if != nil {
panic()
}
return
}
The pages are generated with Golds v0.4.9. (GOOS=linux GOARCH=amd64)