【问题标题】:Checking If Specific JSON Key at a Specific Dynamic Location is Null (error)检查特定动态位置的特定 JSON 密钥是否为空(错误)
【发布时间】:2016-06-09 20:19:19
【问题描述】:

我从服务器接收到一个 JSON 对象,并循环访问该对象以收集某些信息。我首先需要检查特定位置的对象中是否存在某个键。我这样做如下:

if (dataJSONobj.responseText['ops:world-patent-data']['ops:equivalents-inquiry']['ops:inquiry-result'][i]['exchange-documents']['exchange-document']['bibliographic-data']['references-cited']['citation'][j]['nplcit'])
//the key is in there

但是,我每次都会收到此错误:

CaseSelector.js:322 Uncaught TypeError: Cannot read property 'nplcit' of undefined*** when there is not a "nplcit" key. 

我的语法有什么问题?我什至通过询问该密钥是否不等于 null 来尝试相反的操作。

【问题讨论】:

  • 你能发布json对象吗?
  • @bhspencer - [j] 很不稳定。韦斯顿在下面正确回答。

标签: javascript json web-services api


【解决方案1】:

['citation'][j] 不存在,如果这仅在您知道没有 nplcit 键时发生,则两者之间可能存在某种关联。但无论nplcit 是否存在,['citation'][j] 都不存在。

【讨论】:

  • 天哪,你是对的!我一直在撞墙,以为我的语法不对。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-10
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 2019-12-30
  • 1970-01-01
相关资源
最近更新 更多