SBJson  3.0.4
Public Member Functions | Properties
SBJsonStreamParser Class Reference

Parse a stream of JSON data. More...

Inherits NSObject.

List of all members.

Public Member Functions

(SBJsonStreamParserStatus)  - parse:
  Parse some JSON.

Properties

BOOL  supportMultipleDocuments
  Expect multiple documents separated by whitespace.
id< SBJsonStreamParserDelegate >  delegate
  Delegate to receive messages.
NSUInteger  maxDepth
  The max parse depth.
NSString *  error
  Holds the error after SBJsonStreamParserError was returned.

Detailed Description

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

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

Parameters:
data An 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, assign]

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.
- (NSUInteger) maxDepth [read, write, assign]

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

Defaults to 32.

- (BOOL) supportMultipleDocuments [read, write, assign]

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: