UNICORN - iOS
実体メソッド | プロパティ | 全メンバ一覧
SBJsonStreamParser クラス

Parse a stream of JSON data. [詳解]

#import <SBJsonStreamParser.h>

SBJsonStreamParser の継承関係図

実体メソッド

(SBJsonStreamParserStatus) - parse:
 Parse some JSON. [詳解]
 

プロパティ

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

詳解

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.

参照
SBJsonStreamParserAdapter for more information.
Objective-C to JSON

メソッド詳解

- (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.

引数
dataAn NSData object containing the next chunk of JSON
戻り値
  • 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.)

プロパティ詳解

- (id<SBJsonStreamParserDelegate>) delegate
readwriteatomicunsafe_unretained

Delegate to receive messages.

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

覚え書き
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
readwriteatomic

The max parse depth.

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

Defaults to 32.

- (BOOL) supportMultipleDocuments
readwriteatomic

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.

参照
The TweetStream app in the Examples

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