0

I have an app that relies on a web service that I have no control over. I'm currently trying to solve a bug.

In a particular case, an asynchronous HTTP request returns

"<null>"

When this happens I get an exception and my app crashes.

I've tried every method I can think of to test for this in an if statement including comparing various strings, arrays, and testing for the characters < and >. Essentially I want to break from a method if the value is found.

Has anyone run into this before, and how did you solve it?

Many thanks :)

4

2 回答 2

1

您是否尝试过使用以下代码对其进行测试

if (myObject == [NSNull null]) {
    // handle it
} else {
    // 
 }

“NSNull 类定义了一个单例对象,用于在禁止将 nil 作为值的情况下(通常在数组或字典等集合对象中)表示空值。” - 苹果

于 2013-09-08T12:54:10.717 回答
0

好的,我想通了。它一定有助于把问题写下来。我还没有创建一个相同的空对象来比较它。我的 null 对象实际上是由一段 JSON 代码生成的,所以我所要做的就是复制这样的对象并使用 isEqual: 来比较它们。

于 2013-09-10T02:50:41.163 回答