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

Function GetString

parser.go:1855–1875  ·  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

1853// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
1854// If key data type do not match, it will return an error.
1855func GetString(data []byte, keys ...string) (val string, err error) {
1856 v, t, _, e := Get(data, keys...)
1857
1858 if e != nil {
1859 return "", e
1860 }
1861
1862 if t != String {
1863 if t == Null {
1864 return "", NullValueError
1865 }
1866 return "", fmt.Errorf("Value is not a string: %s", string(v))
1867 }
1868
1869 // If no escapes return raw content
1870 if bytes.IndexByte(v, '\\') == -1 {
1871 return string(v), nil
1872 }
1873
1874 return ParseString(v)
1875}
1876
1877// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
1878// The offset is the same as in `Get`.

Calls 2

GetFunction · 0.85
ParseStringFunction · 0.85