javascript - http request and convert to json with comparision of json -


json 1

[

 {         "id": "123",         "testname": "test123",         "name": "john doe",         "active": true,         "type": "test6"     }   {         "id": "456",         "testname": "test564",         "name": "ship therasus",         "active": true,         "type": "test7"     }  .... 100 entries  ]     , json 2 below          [             {                 "id": "123",                 "country": "usa",                 "state": "ka",                 "age": 24,                 "group": "g1"             }           {                 "id": "456",                 "country": "uk",                 "state": "ma",                 "age": 28,                 "group": "g2"             }          ...... 100 entries         ] 

now id constant thing between json1 , json2 want make resultant json below lets call json3.i want match id , country , state json2 , append json1

[     {         "id": "123",         "testname": "test123",         "name": "john doe",         "active": true,         "type": "test6",         "country":"usa",          "state":"ka"     }   {         "id": "456",         "testname": "test564",         "name": "ship therasus",         "active": true,         "type": "test7",          "country":"uk",          "state":"ma"     } ] 

now wat tried 1 , 3 2 dont know wat , compare , combine not sure wat if greatful

function fun()  {   var data="hello";   $.post('http://localhost/ws/service.asmx/helloword',{},function(response)    {     data = response;   }).error(function(){   alert("sorry not proceed"); });      return data; } 

you can try this:

<script> $(document).ready(function(){ var result=[];     var x=[{"id": "123","testname": "test123", "name": "john doe","active": true,"type": "test6"},{"id": "456", "testname": "test564", "name": "ship therasus", "active": true,"type": "test7" }]; var y = [{ "id": "123", "country": "usa", "state": "ka", "age": 24,"group": "g1"},{ "id": "456", "country": "uk", "state": "ma", "age": 28, "group": "g2"}]; (i in x){     (j in y){       if(x[i].id == y[j].id){            result.push($.extend(x[i], y[j]));            }        }    }   console.log(result);  }); </script> 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -