Provides json text parsing support without having to include Newtonsoft Json yourself and
making it work on different platforms easily replacing functionality (like Content.Xml).
View code on GitHub
Inheritance Hierarchy
DeltaEngine.Content.Json JsonNode
Namespace: DeltaEngine.Content.Json
Assembly: DeltaEngine.Content.Json (in DeltaEngine.Content.Json.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The JsonNode type exposes the following members.
Constructors
Name | Description | |
---|---|---|
JsonNode | Initializes a new instance of the JsonNode class |
Methods
Name | Description | |
---|---|---|
Get T | ||
GetIntArray | ||
GetOrDefault T | ||
ToString | (Overrides Object ToString .) |
Properties
Name | Description | |
---|---|---|
Item Int32 | ||
Item String | ||
NumberOfNodes |
Remarks
Examples
[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 ParseEmptyJsonTextIsNotAllowed() { Assert.Throws<JsonNode.NeedValidText>(() => new JsonNode("")); }
See Also