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)
| 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. |
| 2041 | func 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`. |