-
I have the following code: var token // property name, type of string
var array // existing array, type of JsonArray
var newArray = new JsonArray();
array.Select(n => n?[token])
.Where(n => n != null)
.ToList()
.ForEach(n => newArray.Add(n!.AsValue())); However, running this throws the following exception I'm trying to figure out how to create a new |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
A node isn't supposed to be reference in two trees, or two different positions in tree. You must clone it first before adding to another position. |
Beta Was this translation helpful? Give feedback.
-
@huoyaoyuan thanks for your reply. Yes, I'm aware that a node can only have one parent however that doesn't really answer my question. How can I clone a node? I'm unable to find any Please note that I'm trying to avoid having to use serialization/deserialization or reflection. |
Beta Was this translation helpful? Give feedback.
@huoyaoyuan thanks for your reply. Yes, I'm aware that a node can only have one parent however that doesn't really answer my question. How can I clone a node? I'm unable to find any
Clone
method on either the baseJsonNode
nor any derived types such asJsonArray
orJsonObject
.Please note that I'm trying to avoid having to use serialization/deserialization or reflection.