Flex 4.5中JSON检查是否存在异常之前关键的? [英] Flex 4.5 JSON check for existence of key before exception?

查看:113
本文介绍了Flex 4.5中JSON检查是否存在异常之前关键的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能的Flex 4.5 JSON抛出一个异常关键前检查的一个关键的存在,没有发现?我有一些JSON数据,其中某些键并不总是present。

Is it possible to check for the existence of a key before Flex 4.5 JSON throws an exception for key not found? I have some json data where some keys are not always present.

我使用的CallResponder ...

I am using CallResponder...

问题是,当您试图访问 callResponder.lastResponse.key - 并说,关键是不要永远美元的您的JSON p $ psent时,Flex不会能够解析它。出现这种情况,即使你检查如果(callResponder.lastResponse.key) - 发生在当行的错误,在这种情况下

The issue is that when you try accessing callResponder.lastResponse.key - and, say, key is not always present in your json, Flex won't be able to parse it. This happens even if you check if (callResponder.lastResponse.key) - the error occurs on the if line, in that case

(见 rel="nofollow">老错误转储)

(See old error dump here)

下面提供的答案工程,其中键是在JSON顶级节点的情况下。然而,它似乎无法分析存在的子密钥。我没想到那里是顶级节点和子节点解析之间的差别,但显然是这种情况。

The answer provided below works for cases where the keys are top level nodes in the JSON. However, its seems unable to parse existence for child keys. I had not expected there to be a difference between parsing for top level nodes and child nodes, but apparently that is the case.

为了清楚起见(因为我没提到我试图解析的子项在我原来的问题),我已经在这里创造一个新的问题,专门询问如何解析的子密钥,使用下面的方法 - 或另一种方法,如果需要的话:<一href="http://stackoverflow.com/questions/8290577/flex-4-5-how-do-you-check-for-json-child-node-key-existence-using-hasownpropert">Flex 4.5你如何检查JSON子节点存在的关键(使用的hasOwnProperty或其他方法)

For clarity's sake (as I did not mention I am trying to parse for child keys in my original question), I've created a new question here that specifically asks how to parse for child keys, using the method below -- or another method, if need be: Flex 4.5 How do you check for JSON child node key existence (using hasOwnProperty or other methods)

推荐答案

你怎么处理你的JSON数据?

How do you process your JSON data?

在我的记忆中,我使用JSON.de code(字符串),并得到一个数组。对于每一个对象,你可以使用obj.hasOwnProperty(键)来检查它是否是present。

In my memory, I use JSON.decode(String), and got an array. For each object, you can use obj.hasOwnProperty(key) to check whether it's present.

这篇关于Flex 4.5中JSON检查是否存在异常之前关键的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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