如何在JSON.NET中合并/合并两个JArray [英] How to combine/merge two JArrays in JSON.NET

查看:501
本文介绍了如何在JSON.NET中合并/合并两个JArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何连接使用JArray.Parse的两个JArray?数组的顺序必须保留,即第一个数组应该是第一个,然后是几秒钟的元素.

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 element in seconds should come afterwards.

推荐答案

您可以通过调用JArray.Add(element)将元素添加到一个JArray中,其中元素来自第二个JArray.您需要遍历第二个JArray以添加所有这些元素,但这将完成您想要的:

You can add elements to one JArray by calling JArray.Add(element) where element comes from the second JArray. You'll need to loop over the second JArray to add all of these elements, but this will accomplish what you want:

for(int i=0; i<jarrayTwo.Count; i++)
{
    jarrayOne.Add(jarrayTwo[i]);
}

在上面的示例中,

现在将依次包含第一个数组的所有元素,然后是第二个数组的元素.您可以浏览 JArray文档以获得更多详细信息.

in the above example jarrayOne will now contain all of the first array's elements followed by the second array's elements in sequence. You can take a look through the JArray documentation for further details.

这篇关于如何在JSON.NET中合并/合并两个JArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆