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)
| 1487 | // GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols |
| 1488 | // If key data type do not match, it will return an error. |
| 1489 | func GetString(data []byte, keys ...string) (val string, err error) { |
| 1490 | v, t, _, e := Get(data, keys...) |
| 1491 | |
| 1492 | if e != nil { |
| 1493 | return "", e |
| 1494 | } |
| 1495 | |
| 1496 | if t != String { |
| 1497 | if t == Null { |
| 1498 | return "", NullValueError |
| 1499 | } |
| 1500 | return "", fmt.Errorf("Value is not a string: %s", string(v)) |
| 1501 | } |
| 1502 | |
| 1503 | // If no escapes return raw content |
| 1504 | if bytes.IndexByte(v, '\\') == -1 { |
| 1505 | return string(v), nil |
| 1506 | } |
| 1507 | |
| 1508 | return ParseString(v) |
| 1509 | } |
| 1510 | |
| 1511 | // GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. |
| 1512 | // The offset is the same as in `Get`. |