我有两个具有层次结构的对象 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
关于javascript - 如何使用 AngularJs 比较两个对象 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37138861/