How do I merge multiple json objects

不打扰是莪最后的温柔 提交于 2021-01-28 05:09:22

问题


I use different urls get similar json data.

So that I can get more information in the same model

It has trouble me for a long time

i tried to use json.net for a single list.

string url1= "https://apt.data2.com";
string url2= "https://apt.data1.com";
var json1= webClient.DownloadString(url1);
var json2= webClient.DownloadString(url2);

These calls return multiple json objects with the same structure

    {
        data: [
             {
               created_time: "1457332172",
              text: "什麼東西",
              from: {
              username: "d86241",
              profile_picture: "https://scontent.cdninstagram.com/t51.2885-19/s150x150/11371189_421316874725117_327631552_a.jpg",
              id: "397355082",
              full_name: "Jhao-wei Hvang"
    },
    id: "1200511729352353899"
      }
   ]
}

and

{
        data: [
             {
               created_time: "1111",
              text: "hi",
              from: {
              username: "22",
              profile_picture: "",
              id: "ss",
              full_name: "Hvang"
    },
    id: "1200511352353899"
      }
   ]
}

I want to combine these objects to produce

  {
    data:[
    {
      created_time:"1234"
      text:...
       ....
        ......
        },
    id:1234....
      ]

    data:[
    {
      created_time:"4567"
      text:....
       ....
        ......
        },
    id:4567....
      ]
    }

How do I merge these into a single json object?

@foreach (var item in Model)
     {
@ Item.text
    }

回答1:


var jObject1 = // Your first json object as JObject
var jObject2 = // Your second json object as JObject 
jObject1.Merge(jObject2);


来源:https://stackoverflow.com/questions/36147789/how-do-i-merge-multiple-json-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!