Hi all,
I’m trying to serialize a DataTree<int>
into a json string using Newtonsoft’s Json.NET package.
The serialization works just fine and the resulting json string looks like it contains all the necessary info.
The deserialization, however, always gives me and empty tree.
This is what I’m doing:
using Newtonsoft.Json;
// Create a test tree
DataTree<int> testTree = new DataTree<int>();
testTree.Add(0, new GH_Path(0, 1));
testTree.Add(13, new GH_Path(0, 1));
testTree.Add(42, new GH_Path(1, 2));
// Serialize
string testTreeJson = JsonConvert.SerializeObject(testTree);
// Deserialize
DataTree<int> testTreeDeserialized = JsonConvert.DeserializeObject<DataTree<int>>(testTreeJson);
testTreeJson
looks like this:
{
"BranchCount":2,
"DataCount":3,
"Paths":
[
{
"DebuggerDisplay":"{0;1}",
"Indices":[0,1],
"InternalPath":[0,1],
"Length":2,
"Valid":true
},
{
"DebuggerDisplay":"{1;2}",
"Indices":[1,2],
"InternalPath":[1,2],
"Length":2,
"Valid":true
}
],
"Branches":
[
[0,13],
[42]
],
"TopologyDescription":"Tree (Branches = 2)\\r\\n{0;1} (N = 2)\\r\\n{1;2} (N = 1)"
}
However, my testTreeDeserialized
always is empty.
The bad thing is that I don’t have much experience with Json.NET and don’t know if the problem is with Grasshopper or Json.NET…
If anybody has any hints on where to look or some advice it will be greatly apprechiated!
Thanks a lot!
Paul