我有以下 JSON 作为响应:
{
"responseHeader": {
"status": 0,
"QTime": 1
},
"spellcheck": {
"suggestions": [
"goo",
{
"numFound": 4,
"startOffset": 0,
"endOffset": 3,
"suggestion": [
"good",
"google",
"google's",
"goodbye"
]
},
"collation",
"good"
]
}
}
现在基于查询,我有时可能会得到这个 JSON:
{
"responseHeader": {
"status": 0,
"QTime": 1
}
}
当“拼写检查”不存在时,我想检查我的 jQuery 代码。因为否则它会引发异常并且脚本停止执行。
我试过这个:
if(typeof(response.spellcheck)!=='undefined')
但它抛出异常。
帮助。