javascript - 如何使用 AngularJs 比较两个对象 JSON?

标签 javascript angularjs

我有两个具有层次结构的对象 JSON。我需要比较 JSON 中行集中的每个对象。凡是值(value)不相等的地方 然后我必须在相应的对象上添加一个标志。

请查看我的 JSON 并给出解决方案。如果不是 Angular 至少我必须在 Javascript 中实现。

提前致谢...

JSON1

{"entityinfo":{"entity":"Customer29Jan16","tenantid":"292FEC76-5F1C-486F-85A5-09D88096F098","timestamp":"2015-12-15T10:16:06.322Z"},"collections":{"Customer29Jan16":{"rowset":[{"CuId":"123","Name":"Ranjini","Quantity":"60","Rate":"60","Amount":"3600"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]},"Customer29Jan16Obj":{"rowset":[{"CuObjId":"456","FullAddress":"Electronic City","ObjAddr":"Bangalore","ObjName":"Testing"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]}}}

JSON2

{"entityinfo":{"entity":"Customer29Jan16","tenantid":"292FEC76-5F1C-486F-85A5-09D88096F098","timestamp":"2015-12-15T10:16:06.322Z"},"collections":{"Customer29Jan16":{"rowset":[{"CuId":"123","Name":"Vijay","Quantity":"60","Rate":"60","Amount":"3600"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]},"Customer29Jan16Obj":{"rowset":[{"CuObjId":"456","FullAddress":"SilkBoard","ObjAddr":"Bangalore","ObjName":"Testing"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]}}}

最佳答案

使用angular.equals(o1,o2)。它进行深度比较并且不依赖于键的顺序

angular.equals(JSON1, JSON2); // return boolean (true or false) based on the comparison 

引用:Angularjs Docs

关于javascript - 如何使用 AngularJs 比较两个对象 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37138861/

相关文章:

javascript - CSS 主体 100% 高度并在必要时溢出

javascript - React-native-fetch-blob 下载文件

javascript - Aurelia 用模态替换所有浏览器原生确认

javascript - 如何告诉谷歌地图 API 加载脚本在 React 组件中寻找回调?

angularjs - 如何执行单击 Angular Material md-tab

javascript - HTML 文档中的滚动位置 - 如何确定

javascript - 将 URL 参数传递给 AngularJS Controller ?

angularjs - Angular 单元测试: Error: Unexpected request: GET

javascript - 监听复选框并在谷歌地图上显示/隐藏圆形形状(AngularJS)

angularjs - 未定义不是函数是 CoffeeScript/Angular/Jasmine