Playlist Generator  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
Properties
SBJsonStreamParserAdapter Class Reference

SBJsonStreamParserDelegate protocol adapter. More...

#import <SBJsonStreamParserAdapter.h>

Inheritance diagram for SBJsonStreamParserAdapter:
NSObject <SBJsonStreamParserDelegate>

List of all members.

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.

Detailed Description

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;
 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];

Property Documentation

- (id<SBJsonStreamParserAdapterDelegate>) delegate [read, write, retain]

Your delegate object Set this to the object you want to receive the SBJsonStreamParserAdapterDelegate messages.

- (NSUInteger) levelsToSkip [read, write, assign]

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.

See also:
The StreamParserIntegrationTest.m file for examples

The documentation for this class was generated from the following file: