Flex 4.5 如何检查 JSON 子节点键是否存在(使用 hasOwnProperty 或其他方法) [英] Flex 4.5 How do you check for JSON child node key existence (using hasOwnProperty or other methods)

查看:34
本文介绍了Flex 4.5 如何检查 JSON 子节点键是否存在(使用 hasOwnProperty 或其他方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Flex 4.5 中使用 hasOwnProperty(或其他方法)检查​​ JSON 子节点键是否存在?

hasOwnProperty 方法可以检查 JSON 密钥是否存在,但这似乎只适用于 JSON 中的顶级节点,而不适用于子节点.例如,如果您有这样的 JSON 结构(以可读形式,没有 JSON 语法),您可以检查 callresponder.lastResponse.hasOwnKey("Location") 的存在,但似乎无法检查 Location.VenueName 例如或任何孩子:

<前>姓名:地点:(儿童)场地名称:(孩子)地址:(儿童)城市:(儿童)状态:...(等等)

问题在于,当信息不可用时,我的数据源会忽略子键,因此在对其执行任何其他操作之前能够检查 Flex 中的引用中是否存在 JSON 键会很好.

明显的 callresponder.lastResponse.hasOwnKey("Location.VenueName") 不起作用.

问:如何检查 JSON 密钥 Location.VenueName 是否存在?

解决方案

更明显的是

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

哪个应该有效.

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?

解决方案

Even more obvious would be

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

Which should work.

这篇关于Flex 4.5 如何检查 JSON 子节点键是否存在(使用 hasOwnProperty 或其他方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆