Playlist Generator  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
Public Member Functions | Properties
SBJsonStreamParser Class Reference

Parse a stream of JSON data. More...

#import <SBJsonStreamParser.h>

Inheritance diagram for SBJsonStreamParser:
NSObject

List of all members.

Public Member Functions

(SBJsonStreamParserStatus- parse:
 Parse some JSON.

Properties

SBJsonStreamParserStatestate
NSMutableArray * stateStack
BOOL supportMultipleDocuments
 Expect multiple documents separated by whitespace.
id< SBJsonStreamParserDelegatedelegate
 Delegate to receive messages.
NSUInteger maxDepth
 The max parse depth.
NSStringerror
 Holds the error after SBJsonStreamParserError was returned.

Detailed Description

Parse a stream of JSON data.

Using this class directly you can reduce the apparent latency for each download/parse cycle of documents over a slow connection. You can start parsing and return chunks of the parsed document before the entire document is downloaded.

Using this class is also useful to parse huge documents on disk bit by bit so you don't have to keep them all in memory.

See also:
SBJsonStreamParserAdapter for more information.
Objective-C to JSON

Member Function Documentation

- (SBJsonStreamParserStatus) parse: (NSData*)  data

Parse some JSON.

The JSON is assumed to be UTF8 encoded. This can be a full JSON document, or a part of one.

Parameters:
dataAn NSData object containing the next chunk of JSON
Returns:
  • SBJsonStreamParserComplete if a full document was found
  • SBJsonStreamParserWaitingForData if a partial document was found and more data is required to complete it
  • SBJsonStreamParserError if an error occured. (See the error property for details in this case.)

Property Documentation

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

Delegate to receive messages.

The object set here receives a series of messages as the parser breaks down the JSON stream into valid tokens.

Note:
Usually this should be an instance of SBJsonStreamParserAdapter, but you can substitute your own implementation of the SBJsonStreamParserDelegate protocol if you need to.
- (NSString*) error [read, write, copy]

Holds the error after SBJsonStreamParserError was returned.

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

The max parse depth.

If the input is nested deeper than this the parser will halt parsing and return an error.

Defaults to 32.

- (SBJsonStreamParserState*) state [read, write, retain]
- (NSMutableArray*) stateStack [read, assign]
- (BOOL) supportMultipleDocuments [read, write, assign]

Expect multiple documents separated by whitespace.

Normally the -parse: method returns SBJsonStreamParserComplete when it's found a complete JSON document. Attempting to parse any more data at that point is considered an error. ("Garbage after JSON".)

If you set this property to true the parser will never return SBJsonStreamParserComplete. Rather, once an object is completed it will expect another object to immediately follow, separated only by (optional) whitespace.

See also:
The TweetStream app in the Examples

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