<分区>
我有一些 JSON 对象,我想将它们连接成一个 JSON 对象。
我如何使用 NewtonSoft 的 JSON 包来做到这一点?
<分区>
我有一些 JSON 对象,我想将它们连接成一个 JSON 对象。
我如何使用 NewtonSoft 的 JSON 包来做到这一点?
最佳答案
使用 JContainer.Merge()
。
The logic for combining JSON objects together is fairly simple: name/values are copied across, skipping nulls if the existing property already has a value.
例子:
var jObject1 = // Your first json object as JObject
var jObject2 = // Your second json object as JObject
jObject1.Merge(jObject2);
// jObject1 contains now the merged properties from jObject2.
请注意,对于存在于两个对象中的属性,jObject2
优先(即覆盖 jObject1
中的属性)。
关于c# - 如何使用 Json.Net (newtonsoft) 连接两个 Json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26222045/
相关文章:
c# - 无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List` 1
c# - 什么是 XAML 在未处理的异常和 app.g.i.cs 文件上生成中断
c# - Json转换器 : Return a single object or a List<Object> based on inbound JSON
asp.net-mvc - 在 MVC4 项目中使用 Json.NET 序列化器
c# - 从 JsonReader 读取 JObject 时出错。当前 JsonReader 项不是对象 : StartArray. 路径