Newtonsoft.Json.JsonTextReader.ReadAsString C# (CSharp) Method

ReadAsString() public method

Reads the next JSON token from the stream as a String.
public ReadAsString ( ) : string
return string
        public override string ReadAsString()
        {
            return (string)ReadStringValue(ReadType.ReadAsString);
        }

Usage Example

        protected override object DeserializeObject(ArraySegment <byte> value)
        {
            using (var ms = new MemoryStream(value.Array, value.Offset, value.Count, writable: false))
                using (var tr = new StreamReader(ms))
                    using (var jr = new Newtonsoft.Json.JsonTextReader(tr))
                    {
                        jr.Read();
                        if (jr.TokenType == JsonToken.StartArray)
                        {
                            // read type
                            var typeName = jr.ReadAsString();
                            var type     = readCache.GetOrAdd(typeName, x => Type.GetType(x, throwOnError: true)); // Get type or Register type

                            // read object
                            jr.Read();
                            var deserializedValue = jsonSerializer.Deserialize(jr, type);

                            return(deserializedValue);
                        }
                        else
                        {
                            throw new InvalidDataException("JsonTranscoder only supports [\"TypeName\", object]");
                        }
                    }
        }
All Usage Examples Of Newtonsoft.Json.JsonTextReader::ReadAsString