Start Debugging
2023-10-23 更新日 2023-11-01 dotnetdotnet-8 Edit on GitHub

JsonNode .NET 8 の API アップデート

.NET 8 で JsonNode と JsonArray に追加された新しい API、GetValueKind、GetPropertyName、GetElementIndex、ReplaceWith、ParseAsync を解説します。

.NET 8 の一環として、JsonNodeJsonArray の API にいくつかの追加が入っています。ディープコピーとディープイコールについては 以前の記事で取り上げました が、それ以外にもあります。

GetValueKind

public JsonValueKind GetValueKind(JsonSerializerOptions options = null);

現在のインスタンスの JsonValueKind を返します。

GetPropertyName

public string GetPropertyName();

親オブジェクトから見たときの、現在のノードのプロパティ名を返します。親が JsonObject でない場合は InvalidOperationException をスローします。

GetElementIndex

public int GetElementIndex();

JsonArray から見たときの、現在のノードのインデックスを返します。親が JsonArray でない場合は InvalidOperationException をスローします。

ReplaceWith<T>

public void ReplaceWith<T>(T value);

指定したノードを与えられた値で置き換えます。

ParseAsync

public static Task<JsonNode?> ParseAsync(
        Stream utf8Json,
        JsonNodeOptions? nodeOptions = null,
        JsonDocumentOptions documentOptions = default,
        CancellationToken cancellationToken = default);

単一の JSON 値を表す UTF-8 エンコードのデータストリームを、非同期に JsonNode にパースします。

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.

< 戻る