I can't figure out how to concatenate two JArrays that I got by using JArray.Parse? The order of the arrays must be preserved i.e. the first array should be first and element in seconds should come afterwards.
You can use JObject. Merge to merge two different objects into one: JObject o1 = JObject. Parse(@"{ 'FirstName': 'John', 'LastName': 'Smith', 'Enabled': false, 'Roles': [ 'User' ] }"); JObject o2 = JObject.
To do so, we simply need to call the static Parse method from the JObject class, passing as input the JSON string. As output, this method returns the parsed JObject. var jObject1 = JObject. Parse(jsonString1);
Use concat() for arrays Assuming that you would like to merge two JSON arrays like below: var json1 = [{id:1, name: 'xxx' ...}] var json2 = [{id:2, name: 'xyz' ...}]
I used the Merge method, which modifies the original JArray:
JArray test1 = JArray.Parse("[\"john\"]");
JArray test2 = JArray.Parse("[\"doe\"]");
test1.Merge(test2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With