Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用下划线.js将JSON对象响应合并为一个_Javascript_Json_Node.js_Youtube Api_Underscore.js - Fatal编程技术网

Javascript 使用下划线.js将JSON对象响应合并为一个

Javascript 使用下划线.js将JSON对象响应合并为一个,javascript,json,node.js,youtube-api,underscore.js,Javascript,Json,Node.js,Youtube Api,Underscore.js,我正在尝试合并以下两个JSON对象,它们是Youtube API响应 我可能会有数百个视频(一组和两组),我希望它们以以下格式合并成一个JSON *请忽略下面的命名和语法,它们仅用于解释 视频-1:{a:{..},b:{..},视频-2:{a:{..},b:{..},视频-3:{a:{..},b:{..} 只要第二个响应按照设定的顺序附加到第一个响应,我就很高兴。 不像 {a,a,a,a,a},{b,b,b,b,b} 更像 {a,b},{a,b},{a,b},{a,b},{a,b},{a,b}

我正在尝试合并以下两个JSON对象,它们是Youtube API响应

我可能会有数百个视频(一组和两组),我希望它们以以下格式合并成一个JSON

*请忽略下面的命名和语法,它们仅用于解释

视频-1:{a:{..},b:{..},视频-2:{a:{..},b:{..},视频-3:{a:{..},b:{..}

只要第二个响应按照设定的顺序附加到第一个响应,我就很高兴。 不像

{a,a,a,a,a},{b,b,b,b,b}

更像

{a,b},{a,b},{a,b},{a,b},{a,b},{a,b}

我试过了

_.values(_.extend(_.indexBy(array1, 'kind'), _.indexBy(array2, 'kind')))
但它并没有以期望的方式合并。还尝试了u.flatte、u.union、u.defaults,但它们都不适合我

a-播放列表中的视频片段 b-视频内容详细信息
如果您在示例中使用不同的数字,那么对我们来说更有意义,这样我就知道您希望如何在结果中映射它们。如果我知道如何将您的两个来源映射为一个来源,请乐于提供帮助。谢谢您的帮助。你说的数字有多不同?@Will我在示例中使用字母表编辑了我的问题。希望这更清楚。您是否尝试过lodash合并函数
\合并({},objectA,objectB)?@SeongLee-很抱歉我不清楚,但是如果您的所有值和键都是a和b,那么我不知道如何映射到新对象。尽可能避免重复键和值,以便我们了解映射。
{ 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' } },
}
{ 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 ] }