Flex 4.5 How do you check for JSON child node key

2019-09-02 05:45发布

问题:

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.