检查JSON对象中的值 [英] Check for a value in a JSON object
本文介绍了检查JSON对象中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找出ID是否出现在我的JSON对象中,例如:
I need to find out if an id occurs in my JSON object, for example:
{
"requested": "2009-07-25T14:12:25+01:00",
"channels": [
{"id": 1, "name": "General", "created": "2009-07-25 14:00:02"}
]
}
具体来说,我需要检查我的ID(例如2)是否出现在channels.
i
.id
中.该怎么办?
Specifically I need to check if my id (say, 2) occurs in channels.
i
.id
. How can this be done?
推荐答案
尝试一下:
var id = 2,
found = false;
for (var i=0; i<channels.length; i++) {
if (channels[i].id == id) {
found = true;
break;
}
}
这篇关于检查JSON对象中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文