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

Function GetString

parser.go:1947–1967  ·  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

1945// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
1946// If key data type do not match, it will return an error.
1947func GetString(data []byte, keys ...string) (val string, err error) {
1948 v, t, _, e := Get(data, keys...)
1949
1950 if e != nil {
1951 return "", e
1952 }
1953
1954 if t != String {
1955 if t == Null {
1956 return "", NullValueError
1957 }
1958 return "", fmt.Errorf("Value is not a string: %s", string(v))
1959 }
1960
1961 // If no escapes return raw content
1962 if bytes.IndexByte(v, '\\') == -1 {
1963 return string(v), nil
1964 }
1965
1966 return ParseString(v)
1967}
1968
1969// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
1970// The offset is the same as in `Get`.

Calls 2

GetFunction · 0.85
ParseStringFunction · 0.85