Merge two JTokens into one

后端 未结 2 692
星月不相逢
星月不相逢 2020-12-07 02:28

How can I merge these two JTokens into one single JToken. This sounds like it should be simple, but can\'t get my way around it.

{
  \"data\":[
  {
      \"I         


        
2条回答
  •  抹茶落季
    2020-12-07 02:42

    You could merge it like that (or if you had it had it in an array or list you could make a linq group by query for example over the ID property, that would be likewise effective).

      var data1 =  JObject.Parse(@"{
               'data':[
              {
                 'ID':'53a1862000404a304942546b35519ba3',
                  'name':'Private Approval Process: Draft Document CPL',
                  'objCode':'ARVPTH'
              }]
            }");
    
            var data2 = JObject.Parse(@"{
               'data':[
              {
                 'ID':'53a1862000404a304942546b35519ba3',
                  'name':'Private Approval Process: Draft Document CPL',
                  'objCode':'ARVPTH'
              }]
            }");
    
            data1.Merge(data2, new JsonMergeSettings
            {
               MergeArrayHandling = MergeArrayHandling.Union
            });
    
            string json = data1.ToString();
    

提交回复
热议问题