Yes, you can use JsonConvert.PopulateObject()
to fill in properties on an existing object from a second JSON string.
Here is an example:
string json1 = @"
{
""CID"": ""13579"",
""jsonrpc"": ""something"",
""id"": ""24680""
}";
Account account = JsonConvert.DeserializeObject<Account>(json1);
string json2 = @"
{
""mail"": [ ""abc@example.com"", ""def@example.org"" ],
""uid"": [ ""87654"", ""192834"" ],
""userPassword"": [ ""superSecret"", ""letMeInNow!"" ]
}";
JsonConvert.PopulateObject(json2, account);
Console.WriteLine("CID: " + account.CID);
Console.WriteLine("jsonrpc: " + account.jsonrpc);
Console.WriteLine("id: " + account.id);
Console.WriteLine("mail: " + string.Join(", ", account.mail));
Console.WriteLine("uid: " + string.Join(", ", account.uid));
Console.WriteLine("userPassword: " + string.Join(", ", account.userPassword));
Output:
CID: 13579
jsonrpc: something
id: 24680
mail: abc@example.com, def@example.org
uid: 87654, 192834
userPassword: superSecret, letMeInNow!
Fiddle: https://dotnetfiddle.net/621bfV
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…