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...
Cœur
  • 37,241
  • 25
  • 195
  • 267
gurghet
  • 7,591
  • 4
  • 36
  • 63

1 Answers1

0

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
  • 9,037
  • 3
  • 34
  • 50
  • what does it mean? If it's not a NSMutableArray, but a subclass of it, what is it then? – gurghet Sep 20 '10 at 12:59
  • 2
    `NS(Mutable)Array` is a class cluster: http://developer.apple.com/library/ios/#documentation/General/Conceptual/DevPedia-CocoaCore/ClassCluster.html – Wevah Sep 20 '10 at 13:59