我正在使用instagram API,如果标题不存在或没有文本,它根本不包含节点。所以我包括一个检查,看看是否存在标题工作,但如果标题存在和子节点文本不,然后我得到的错误:Uncaught TypeError: Cannot read property 'text' of null
。JSON未捕获类型错误
这是我的代码:
for (p in pictures) {
if (pictures[p].hasOwnProperty('caption')) {
if (pictures[p].caption.text != null) {
captionString = pictures[p].caption.text;
}
}
}
如果标题为空,则没有标题? (但是一个标题属性在这里通知你没有可用的标题),所以只有当标题属性不为空时,你才应该添加一个标题字符串 – Hacketo