如何使JSON数组唯一 [英] How to make a JSON array unique
本文介绍了如何使JSON数组唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
数组唯一值
获取使用jQuery的JSON数组的独特结果
我有一个这样的JSON字符串
Im having a JSON string like this
[
Object { id="38",product="foo"},
Object { id="38",product="foo"},
Object { id="38",product="foo"},
Object { id="39",product="bar"},
Object { id="40",product="hello"},
Object { id="40",product="hello"}
]
这个JSON数组中有重复的值。我可以使这个JSON数组独一无二吗
There are duplicate values in this JSON array..how can i make this JSON array unique like this
[
Object { id="38",product="foo"},
Object { id="39",product="bar"},
Object { id="40",product="hello"}
]
。查找使用较少迭代的建议,
Jquery $ .inArray
在这种情况下不起作用。
.Im looking for a suggestion that uses less iterations,
Jquery $.inArray
is not working in this case.
欢迎使用任何第三方库的建议。
Suggestion to use any third party libraries are welcome.
推荐答案
在以下SO问题中检查解决方案:
Check the solution in the following SO question:
您必须遍历数组并创建一个新数组包含唯一的值。
You'll have to iterate through your array and create a new array which contains unique values.
这篇关于如何使JSON数组唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文