fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

Provide a GetString to get string type instead of byte slice

Open goodspark opened this issue 5 years ago • 1 comments

Could we get a function to just return the string type instead of a byte slice?

I often just need the string and noticed GetStringByte is actually converting the underlying string to a byte.

func (v *Value) GetString(keys ...string) string {
  v = v.Get(keys...)
  if v == nil || v.Type() != TypeString {
    return ""
  }
  return v.s
}

goodspark avatar Feb 29 '20 23:02 goodspark

This won't work, since v.s is backed by byte slice, which changes on the next Parser.Parse call. This means that the returned string contents will become garbage on the next Parser.Parse call.

valyala avatar Mar 03 '20 21:03 valyala