javascript - http request and convert to json with comparision of json -
- i want make http request url lets http://test1.com/info give me xml
- i want convert xml 1 json lets json 1
- now make rest request url lets http://test2.com/myweb returns json lets json 2
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
Post a Comment