UNICORN - iOS
プロパティ | 全メンバ一覧
SBJsonStreamParserAdapter クラス

SBJsonStreamParserDelegate protocol adapter. [詳解]

#import <SBJsonStreamParserAdapter.h>

SBJsonStreamParserAdapter の継承関係図
<SBJsonStreamParserDelegate>

プロパティ

NSUInteger levelsToSkip
 How many levels to skip. [詳解]
 
id< SBJsonStreamParserAdapterDelegatedelegate
 Your delegate object Set this to the object you want to receive the SBJsonStreamParserAdapterDelegate messages.
 

その他の継承メンバ

- 基底クラス <SBJsonStreamParserDelegate> に属する継承実体メソッド
(void) - parserFoundObjectStart:
 Called when object start is found.
 
(void) - parser:foundObjectKey:
 Called when object key is found.
 
(void) - parserFoundObjectEnd:
 Called when object end is found.
 
(void) - parserFoundArrayStart:
 Called when array start is found.
 
(void) - parserFoundArrayEnd:
 Called when array end is found.
 
(void) - parser:foundBoolean:
 Called when a boolean value is found.
 
(void) - parserFoundNull:
 Called when a null value is found.
 
(void) - parser:foundNumber:
 Called when a number is found.
 
(void) - parser:foundString:
 Called when a string is found.
 

詳解

SBJsonStreamParserDelegate protocol adapter.

Rather than implementing the SBJsonStreamParserDelegate protocol yourself you will most likely find it much more convenient to use an instance of this class and implement the SBJsonStreamParserAdapterDelegate protocol instead.

The default behaviour is that the delegate only receives one call from either the -parser:foundArray: or -parser:foundObject: method when the document is fully parsed. However, if your inputs contains multiple JSON documents and you set the parser's -supportMultipleDocuments property to YES you will get one call for each full method.

SBJsonStreamParserAdapter *adapter = [[[SBJsonStreamParserAdapter alloc] init] autorelease];
adapter.delegate = self;
SBJsonStreamParser *parser = [[[SBJsonStreamParser alloc] init] autorelease];
parser.delegate = adapter;
// Note that this input contains multiple top-level JSON documents
NSData *json = [@"[]{}[]{}" dataWithEncoding:NSUTF8StringEncoding];
[parser parse:data];

In the above example self will have the following sequence of methods called on it:

Often you won't have control over the input you're parsing, so can't make use of this feature. But, all is not lost: this class will let you get the same effect by allowing you to skip one or more of the outer enclosing objects. Thus, the next example results in the same sequence of -parser:foundArray: / -parser:foundObject: being called on your delegate.

SBJsonStreamParserAdapter *adapter = [[[SBJsonStreamParserAdapter alloc] init] autorelease];
adapter.delegate = self;
adapter.levelsToSkip = 1;
SBJsonStreamParser *parser = [[[SBJsonStreamParser alloc] init] autorelease];
parser.delegate = adapter;
// Note that this input contains A SINGLE top-level document
NSData *json = [@"[[],{},[],{}]" dataWithEncoding:NSUTF8StringEncoding];
[parser parse:data];

プロパティ詳解

- (NSUInteger) levelsToSkip
readwriteatomic

How many levels to skip.

This is useful for parsing huge JSON documents, or documents coming in over a very slow link.

If you set this to N it will skip the outer N levels and call the -parser:foundArray: or -parser:foundObject: methods for each of the inner objects, as appropriate.

参照
The StreamParserIntegrationTest.m file for examples

このクラス詳解は次のファイルから抽出されました: