views:

61

answers:

1
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableArray *componenti = [parser
                               objectWithString:@"[\"Item1\",\"Item2\"]"];
NSAssert([componenti isMemberOfClass:[NSMutableArray class]],@"err");

This code gives me an assertion failed. What is wrong?

The header file says:

@brief The JSON parser class.

JSON is mapped to Objective-C types in the following way:

@li Null -> NSNull
@li String -> NSMutableString
@li Array -> NSMutableArray
etc...
A: 

use NSAssert([componenti isKindOfClass:[NSMutableArray class]],@"err"); instead.

I never really investigated this behavior but it seems that every time you instantiate a NSMutableArray, you received an instance of __NSArrayM in return. __NSArrayM is a subclass of NSMutableArray.

And btw, SBJson is an excellent parser and I use it for a while now.

VdesmedT
what does it mean? If it's not a NSMutableArray, but a subclass of it, what is it then?
gurghet
`NS(Mutable)Array` is a class cluster: http://developer.apple.com/library/ios/#documentation/General/Conceptual/DevPedia-CocoaCore/ClassCluster.html
Wevah