Merge two JSON objects programmatically

后端 未结 8 991
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 02:01

I have two JSON objects here, generated through the Google Search API. The URL\'s of these objects can be found below.

http://ajax.googleapis.com/ajax/services/searc

8条回答
  •  遥遥无期
    2020-12-17 02:33

    I'm not sure how you'd merge these things completely, given that there's a lot of extra data in each apart from the results themselves, but if you just want a JavaScript array containing all 16 results, this should work...

    var responses = [GetJsonObjectFromThatUriUsingJqueryOrSomething(),
                     GetJsonObjectFromThatOtherUriUsingJqueryOrSomething()];
    
    // Probably want to check for success
    // and ensure that responses[i].responseData.results is valid.
    
    var results = [];
    for (var i = 0; i < responses.length; ++i)
    {
        results = results.concat(responses[i].responseData.results);
    }
    

提交回复
热议问题