JsonDocument.TryParseValue(Utf8JsonReader, JsonDocument) 方法


會嘗試從提供的讀取器剖析一個 JSON 值 (包括物件或陣列)。Attempts to parse one JSON value (including objects or arrays) from the provided reader.

 static bool TryParseValue(System::Text::Json::Utf8JsonReader % reader, [Runtime::InteropServices::Out] System::Text::Json::JsonDocument ^ % document);
public static bool TryParseValue (ref System.Text.Json.Utf8JsonReader reader, out System.Text.Json.JsonDocument document);
static member TryParseValue : Utf8JsonReader * JsonDocument -> bool
Public Shared Function TryParseValue (ByRef reader As Utf8JsonReader, ByRef document As JsonDocument) As Boolean



要讀取的讀取器。The reader to read.


當這個方法傳回時,會包含剖析的文件。When the method returns, contains the parsed document.


如果已讀取值並已將其剖析為 JsonDocument,則為 true;如果讀取器在剖析時用盡資料,則為 falsetrue if a value was read and parsed into a JsonDocument; false if the reader ran out of data while parsing. 所有其他情況都會導致擲回例外狀況。All other situations result in an exception being thrown.


reader 包含不支援的選項。reader contains unsupported options.


目前的 reader 權杖不會啟動或表示值。The current reader token does not start or represent a value.

無法從讀取器讀取某個值。A value could not be read from the reader.


如果 readerTokenType 屬性 JsonTokenType.PropertyNameJsonTokenType.None,讀取器將會藉由一個呼叫 Utf8JsonReader.Read() 來前進,以判斷值的開頭。If the TokenType property of reader is JsonTokenType.PropertyName or JsonTokenType.None, the reader will advance by one call to Utf8JsonReader.Read() to determine the start of the value.

完成這個方法時,reader 位於 JSON 值中的最後一個 token。Upon completion of this method, reader is positioned at the final token in the JSON value. 如果擲回例外狀況或傳回 false,則讀取器會重設為呼叫方法時所處的狀態。If an exception is thrown or false is returned, the reader is reset to the state it was in when the method was called.

這個方法會複製讀取器所處理的資料,因此不需要在傳回此方法的情況下維持資料完整性。This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.