How to combine/merge two JArrays in JSON.NET

前端 未结 4 1105
半阙折子戏
半阙折子戏 2021-01-04 02:38

I can\'t figure out how to concatenate two JArrays that I got be using JArray.Parse? The order of the arrays must be preserved i.e. the first array should be first and eleme

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 03:00

    My two cents for the generic case where you have n JArray's:

    IEnumerable jarrays = ...
    var concatenated = new JArray(jarrays.SelectMany(arr => arr));
    

    And to project this onto the original question with two JArray's:

    JArray jarr0 = ...
    JArray jarr1 = ...
    var concatenated = new JArray(new[] { jarr0, jarr1 }.SelectMany(arr => arr));
    

提交回复
热议问题