Merge two JSON objects programmatically

后端 未结 8 971
被撕碎了的回忆
被撕碎了的回忆 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:27

    If you are up to a client side solution(JavaScript actually) what about trying the "unite" function I have written: http://code.google.com/p/av-jslib/source/browse/js/aV.ext.object.js#36

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
提交回复
热议问题