如何将2个json提要中的数据推送到单个数组中

时间:2013-02-27 08:55:16

标签: jquery ajax json

根据标题,我有2个json feed,我正在尝试使用它。出发机场飞往哪个目的地机场的第一个细节,第二个我想用来查找飞往哪些机场的友好名字的细节。我有一组信息页面。我想从这两个Feed中动态输出每页飞行的目的地列表。我不清楚如何将这些推送到一个数组和排序等等。任何帮助非常感谢。

第一次投稿

$.ajax({
  url: '/routesRouteInformation.action',
  async: false,
  dataType: 'json',
  success: function (response) {
  jsonRoutes = response;
  }
});

示例文件:

{
"LGW":[
 {"arvAirportCode":"EDI","multiSector":"M","endDate":"26-Oct-2013 00:00:00"},
 {"arvAirportCode":"NCL","multiSector":"D","endDate":"26-Oct-2013 00:00:00"},
 {"arvAirportCode":"SYY","multiSector":"M","endDate":"26-Oct-2013 00:00:00"},
 ...Etc

第二次投放

$.ajax({
  url: '/airportsRouteInformation.action',
  async: false,
  dataType: 'json',
  success: function (response) {
  jsonInfo = response;
  }
});

示例文件:

[{"airportCode":"LGW","airportCountry":"UK","airportName":"London Gatwick", "longitude":"53.910297","latitude":"-8.818492"},
"airportCode":"BLL","airportCountry":"DK","airportName":"Billund","longitude":"55.740322","latitude":"9.151778"},
{"airportCode":"RNN","airportCountry":"DK","airportName":"Bornholm"},    {"airportCode":"BCN","airportCountry":"ES","airportName":"Barcelona","longitude":"41.2969","latitude":"2.07833"}
...Etc

2 个答案:

答案 0 :(得分:0)

尝试

$.extend(object1, object2);

答案 1 :(得分:0)

根据您的数据,我会首先检索机场信息,然后检索路线中的每个机场信息查询并将其添加到路线中。 一些事情:

$.each(infos, function(index, info){
info.routes = routes[info.airportCode];
});