给定一个像这样的 json 字符串:
[{"id":28,"Title":"Sweden"},{"id":56,"Title":"USA"},{"id":89,"Title":"England"}]
我需要检查一个对象是否存在,检查所有字段,意思是:
{"id":28,"Title":"Sweden"} => exists
{"id":29,"Title":"Sweden"} => doesn't exist
或者
{"id":28,"Title":"Sweden"} => exists
{"id":28,"Title":"Sweden2"} => doesn't exist
集合可能有任意数量的对象,并且对象总是有相同数量的属性(id、title)或(id、title、firstName)等。
另外,为了检查现有对象,是否需要将字符串解析为 json 对象集合?
我试过这个:
$.map(val, function (obj) {
if (obj === val)
alert('in');
return obj; // or return obj.name, whatever.
});