Anton Anton - 3 months ago 80
C# Question

Merge two Json.NET JTokens

I have two

JToken
's that represent JSON arrays of objects and I would like to merge them.
JToken
has a method
Concat
but it produces
null
as result when I try to use it.

Action<JToken> Ok = (x) =>
{
Debug.WriteLine(x);
/* outputs
[
{
"id": 1,
},
{
"id": 2,
}
]
*/

x = (x).Concat<JToken>(x) as JToken;
Debug.WriteLine(x); // null
};


How can I make it work?

Answer
JToken.FromObject(x.Concat(x))