Flex 4.5 How do you check for JSON child node key existence (using hasOwnProperty or other methods)

筅森魡賤 提交于 2020-01-06 19:50:28

问题


How do you check for JSON child node key existence using hasOwnProperty (or other methods) in Flex 4.5?

The hasOwnProperty method can check for JSON key existence but this seems to only work with top level nodes in a JSON, and not the child nodes. For example, if you have JSON structure like this (in a readable form, sans the JSON syntax), you can check for the existence of callresponder.lastResponse.hasOwnKey("Location"), but there seems no way to check for Location.VenueName for example or any of the children:

Name: 
Location: 
  (child) VenueName: 
  (child) Address: 
      (child) City: 
      (child) State: 
  .
  .
  . (etc)

The issue is that my data source omits the child key when the information is not available, so it would be nice to be able to check for the existence of the JSON key in a reference in Flex before doing anything else for it.

The obvious callresponder.lastResponse.hasOwnKey("Location.VenueName") does not work.

Q: How would I check if the JSON key Location.VenueName exists?


回答1:


Even more obvious would be

callresponder.lastResult.Location.hasOwnProperty("VenueName");

Which should work.



来源:https://stackoverflow.com/questions/8290577/flex-4-5-how-do-you-check-for-json-child-node-key-existence-using-hasownpropert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!