JsonNode NumberOfNodes Property Delta Engine Documentation

Namespace: DeltaEngine.Content.Json
Assembly: DeltaEngine.Content.Json (in DeltaEngine.Content.Json.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public int NumberOfNodes { get; }

Property Value

Type: Int32
Remarks

Tests: DeltaEngine.Content.Json.Tests.JsonNodeTests
Examples

6 unit tests call DeltaEngine.Content.Json.JsonNode.NumberOfNodes
[Test]
public void ReadJsonWithChildrenNodes()
{
    var json = new JsonNode("{ \"Child1\": { \"Number\":1 }, \"Child2\": { \"Number\":2 } }");
    Assert.AreEqual(2, json.NumberOfNodes);
    Assert.AreEqual(1, json["Child1"].Get<int>("Number"));
    Assert.AreEqual(2, json["Child2"].Get<int>("Number"));
}
[Test]
public void ParseBooleansStringsAndNumbers()
{
    var json = new JsonNode("{ \"Flag\": true, \"SomeNumber\": 1.23, \"Text\": \"blub\" }");
    Assert.AreEqual(3, json.NumberOfNodes);
    Assert.IsTrue(json.Get<bool>("Flag"));
    Assert.AreEqual(1.23f, json.Get<float>("SomeNumber"));
    Assert.AreEqual("blub", json.GetOrDefault("Text", ""));
}
[Test]
public void EmptyJsonShouldHaveZeroNodes()
{
    var json = new JsonNode("{}");
    Assert.AreEqual(0, json.NumberOfNodes);
}
See Also