将两个JSON对象与Underscore.js合并

时间:2015-12-22 09:27:55

标签: json node.js underscore.js

我尝试合并以下2个JSON对象,即Youtube API响应。我试过了

_.values(_.extend(_.indexBy(array1, 'kind'), _.indexBy(array2, 'kind')))

但它没有正确合并。我已经尝试了_.flatten,_。union,_.defaults,但它们都不适合我。

1

{ kind: 'youtube#playlistItem',
       etag: '"kuL0kDMAqRo3pU7O0pwlO-Lfzp4/tGxY5umSWnuSkk1adS4H8nsd7nI"',
       id: 'PLhAf_GEuRunTjOdIMNbFsPSMLcbkw3RoTqruH97SaMEs',
       snippet: 
        { publishedAt: '2015-12-13T12:16:47.000Z',
          channelId: 'UCwy6X3JB24VTsDFqMwdO5Jg',
          title: 'John Hockenberry: We are all designers',
          description: 'http://www.ted.com Journalist John Hockenberry tells a personal story inspired by a pair of flashy wheels in a wheelchair-parts catalogue -- and how they showed him the value of designing a life of intent. (From The Design Studio session at TED2012, guest-curated by Chee Pearlman and David Rockwell.)\n\nTEDTalks is a daily video podcast of the best talks and performances from the TED Conference, where the world\'s leading thinkers and doers give the talk of their lives in 18 minutes. Featured speakers have included Al Gore on climate change, Philippe Starck on design, Jill Bolte Taylor on observing her own stroke, Nicholas Negroponte on One Laptop per Child, Jane Goodall on chimpanzees, Bill Gates on malaria and mosquitoes, Pattie Maes on the "Sixth Sense" wearable tech, and "Lost" producer JJ Abrams on the allure of mystery. TED stands for Technology, Entertainment, Design, and TEDTalks cover these topics as well as science, business, development and the arts. Closed captions and translated subtitles in a variety of languages are now available on TED.com, at http://www.ted.com/translate\n\nIf you have questions or comments about this or other TED videos, please go to http://support.ted.com',
          thumbnails: 
           { default: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/default.jpg',
                width: 120,
                height: 90 },
             medium: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/mqdefault.jpg',
                width: 320,
                height: 180 },
             high: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/hqdefault.jpg',
                width: 480,
                height: 360 },
             standard: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/sddefault.jpg',
                width: 640,
                height: 480 },
             maxres: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/maxresdefault.jpg',
                width: 1280,
                height: 720 } },
          channelTitle: 'Seong Lee',
          playlistId: 'PLy7hFLa6kbitaVkEcgPEt6GlfVjuyO91K',
          position: 30,
          resourceId: { kind: 'youtube#video', videoId: 'ti_i-M3pk5M' } },
       contentDetails: { videoId: 'ti_i-M3pk5M' } },
}

2

{ kind: 'youtube#videoListResponse',
    etag: '"kuL0kDMAqRo3pU7O0pwlO-Lfzp4/BQsUkCeR_vYw5Am_P0zDQ65R2RI"',
    pageInfo: { totalResults: 1, resultsPerPage: 1 },
    items: 
     [ { kind: 'youtube#video',
         etag: '"kuL0kDMAqRo3pU7O0pwlO-Lfzp4/63882pNOoZMxxAveXDjjDGxrL6g"',
         id: 'ti_i-M3pk5M',
         contentDetails: 
          { duration: 'PT19M44S',
            dimension: '2d',
            definition: 'hd',
            caption: 'true',
            licensedContent: true } },
       [length]: 1 ] }

0 个答案:

没有答案