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

Method GetString

reader_parser.go:89–110  ·  view source on GitHub ↗

GetString returns and decodes the string addressed by keys. SYS-REQ-116

(keys ...string)

Source from the content-addressed store, hash-verified

87// GetString returns and decodes the string addressed by keys.
88// SYS-REQ-116
89func (rp *ReaderParser) GetString(keys ...string) (string, error) {
90 value, vt, err := rp.Get(keys...)
91 if err != nil {
92 return "", err
93 }
94 if vt != String {
95 if vt == Null {
96 return "", NullValueError
97 }
98 return "", valueTypeError("string", value)
99 }
100 if bytes.IndexByte(value, '\\') == -1 {
101 return string(value), nil
102 }
103
104 var stackbuf [unescapeStackBufSize]byte
105 unescaped, err := unescapeConfig(rp.config, value, stackbuf[:])
106 if err != nil {
107 return "", MalformedValueError
108 }
109 return string(unescaped), nil
110}
111
112// ArrayEach incrementally iterates a root JSON array. Callback value slices are
113// valid for the duration of the callback and must be copied if retained.

Calls 3

GetMethod · 0.95
valueTypeErrorFunction · 0.85
unescapeConfigFunction · 0.85