开发者

How does the objective-c SBJson library map an array? (do you recommend it?)

开发者 https://www.devze.com 2023-01-17 07:29 出处:网络
SBJsonParser *parser = [[SBJsonParser alloc] init]; NSMutableArray *componenti = [parser objectWithString:@\"[\\\"Item1\\\",\\\"Item2\\\"]\"];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableArray *componenti = [parser
                               objectWithString:@"[\"Item1\",\"Item2\"]"];
NSAssert([componenti isMemberOfClass:[NSMutableArray class]],@"err");

T开发者_开发问答his 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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消