使用唯一键从Json对象获取值

时间:2022-12-22 23:49:56

How do I check if a JSON object have key are duplicate, just get distint the key and not use foreach function? Such as:

如何检查JSON对象是否有重复密钥,只是获取密钥而不使用foreach函数?如:

var objectData = {[value1: abc], [value1: abc], [value2: bcd]}

If a key doesn't exist, and I try to access it, will it return undefined? Or get the error?

如果某个键不存在,并且我尝试访问它,它是否会返回undefined?或者得到错误?

1 个解决方案

#1


0  

If this is meant to be an array of JSON objects:

如果这是一个JSON对象数组:

var objectData = [ {"value1": "abc"}, {"value1": "abc"}, {"value2": "bcd"} ];

Then your answer lies within the responses to this question: Remove duplicates from an array of objects in javascript or this one Remove duplicate objects from an array using javascript.

然后你的答案就在这个问题的回答中:从javascript中的一个对象数组中删除重复项,或者使用javascript从数组中删除重复的对象。

If your notation accurately reflects what is produced by your system (or your own coding), you may want to rework it a bit so it makes sense.

如果您的符号准确地反映了您的系统(或您自己的编码)产生的内容,您可能需要稍微修改它以使其有意义。

Hope that helps.

希望有所帮助。

#1


0  

If this is meant to be an array of JSON objects:

如果这是一个JSON对象数组:

var objectData = [ {"value1": "abc"}, {"value1": "abc"}, {"value2": "bcd"} ];

Then your answer lies within the responses to this question: Remove duplicates from an array of objects in javascript or this one Remove duplicate objects from an array using javascript.

然后你的答案就在这个问题的回答中:从javascript中的一个对象数组中删除重复项,或者使用javascript从数组中删除重复的对象。

If your notation accurately reflects what is produced by your system (or your own coding), you may want to rework it a bit so it makes sense.

如果您的符号准确地反映了您的系统(或您自己的编码)产生的内容,您可能需要稍微修改它以使其有意义。

Hope that helps.

希望有所帮助。