-Merge demo

This commit is contained in:
James Newton-King
2014-08-03 18:56:41 +12:00
parent 8e727a27b2
commit 3327a6954c
4 changed files with 40 additions and 1 deletions
+35
View File
@@ -29,6 +29,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Serialization;
#if !NETFX_CORE
@@ -515,5 +516,39 @@ namespace Newtonsoft.Json.Tests
// "address": "221B Baker Street"
// }
}
[Test]
public void MergeJson()
{
JObject o1 = JObject.Parse(@"{
'FirstName': 'John',
'LastName': 'Smith',
'Enabled': false,
'Roles': [ 'User' ]
}");
JObject o2 = JObject.Parse(@"{
'Enabled': true,
'Roles': [ 'User', 'Admin' ]
}");
o1.Merge(o2, new JsonMergeSettings
{
// union arrays together to avoid duplicates
MergeArrayHandling = MergeArrayHandling.Union
});
string json = o1.ToString();
// {
// "FirstName": "John",
// "LastName": "Smith",
// "Enabled": true,
// "Roles": [
// "User",
// "Admin"
// ]
// }
Console.WriteLine(json);
}
}
}