MCPcopy Create free account
hub / github.com/buger/jsonparser / GetString

Function GetString

parser.go:2041–2061  ·  view source on GitHub ↗

SYS-REQ-002, SYS-REQ-071, SYS-REQ-072, SYS-REQ-073, SYS-REQ-074 GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols If key data type do not match, it will return an error.

(data []byte, keys ...string)

Source from the content-addressed store, hash-verified

2039// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
2040// If key data type do not match, it will return an error.
2041func GetString(data []byte, keys ...string) (val string, err error) {
2042 v, t, _, e := Get(data, keys...)
2043
2044 if e != nil {
2045 return "", e
2046 }
2047
2048 if t != String {
2049 if t == Null {
2050 return "", NullValueError
2051 }
2052 return "", fmt.Errorf("Value is not a string: %s", string(v))
2053 }
2054
2055 // If no escapes return raw content
2056 if bytes.IndexByte(v, '\\') == -1 {
2057 return string(v), nil
2058 }
2059
2060 return ParseString(v)
2061}
2062
2063// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
2064// The offset is the same as in `Get`.

Calls 2

GetFunction · 0.85
ParseStringFunction · 0.85