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

Function GetString

parser.go:1928–1948  ·  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

1926// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
1927// If key data type do not match, it will return an error.
1928func GetString(data []byte, keys ...string) (val string, err error) {
1929 v, t, _, e := Get(data, keys...)
1930
1931 if e != nil {
1932 return "", e
1933 }
1934
1935 if t != String {
1936 if t == Null {
1937 return "", NullValueError
1938 }
1939 return "", fmt.Errorf("Value is not a string: %s", string(v))
1940 }
1941
1942 // If no escapes return raw content
1943 if bytes.IndexByte(v, '\\') == -1 {
1944 return string(v), nil
1945 }
1946
1947 return ParseString(v)
1948}
1949
1950// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
1951// The offset is the same as in `Get`.

Calls 2

GetFunction · 0.85
ParseStringFunction · 0.85