SBJson 3.0.4
|
SBJsonStreamParserDelegate protocol adapter. More...
List of all members.
Public Member Functions |
|
(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. |
|
Properties |
|
NSUInteger | levelsToSkip |
How many levels to skip. |
|
id < SBJsonStreamParserAdapterDelegate > |
delegate |
Your delegate object Set this to the object you want to receive the SBJsonStreamParserAdapterDelegate messages. |
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.
Normally you would only get one call from either the -parser:foundArray: or -parser:foundObject: method. 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; parser.supportMultipleDocuments = YES; // 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 [read, write, assign]
|
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.