/// <summary> /// Parses the current JSON token value from the source, unescaped, and transcoded as a <see cref="string"/>. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if trying to get the value of the JSON token that is not a string /// (i.e. other than <see cref="JsonTokenType.String"/> or <see cref="JsonTokenType.PropertyName"/>). /// <seealso cref="TokenType" /> /// It will also throw when the JSON string contains invalid UTF-8 bytes, or invalid UTF-16 surrogates. /// </exception> public string GetString() { if (TokenType != JsonTokenType.String && TokenType != JsonTokenType.PropertyName) { throw ThrowHelper.GetInvalidOperationException_ExpectedString(TokenType); } ReadOnlySpan <byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan; if (_stringHasEscaping) { int idx = span.IndexOf(JsonConstants.BackSlash); Debug.Assert(idx != -1); return(JsonReaderHelper.GetUnescapedString(span, idx)); } Debug.Assert(span.IndexOf(JsonConstants.BackSlash) == -1); return(JsonReaderHelper.TranscodeHelper(span)); }