更新时间:2022-12-27 22:34:09
使用JContainer.Merge()
.
将JSON对象组合在一起的逻辑非常简单:名称/值被复制,如果现有属性已经具有值,则跳过null.
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
中的属性).
Note that for properties that exist in both objects, the jObject2
ones take precedence (i.e. overwrite the properties in jObject1
).