Public Member Functions | Protected Attributes | Properties

YAJLDocument Class Reference

JSON document interface. More...

#import <YAJLDocument.h>

Inheritance diagram for YAJLDocument:
<YAJLParserDelegate>

List of all members.

Public Member Functions

(id) - initWithData:parserOptions:error:
 Delegate.
(id) - initWithData:parserOptions:capacity:error:
 Create document from data.
(id) - initWithParserOptions:
 Create empty document with parser options.
(id) - initWithParserOptions:capacity:
 Create empty document with parser options.
(YAJLParserStatus) - parse:error:
 Parse data.
(void) - _pop
(void) - _popKey

Protected Attributes

id root_
YAJLParserparser_
id< YAJLDocumentDelegatedelegate_
__weak NSMutableDictionary * dict_
__weak NSMutableArray * array_
__weak NSString * key_
NSMutableArray * stack_
NSMutableArray * keyStack_
YAJLDecoderCurrentType currentType_
YAJLParserStatus parserStatus_

Properties

id root
YAJLParserStatus parserStatus
 The root element of the document, either NSArray or NSDictionary.
id< YAJLDocumentDelegatedelegate
 The current status of parsing.

Detailed Description

JSON document interface.

 NSData *data = [NSData dataWithContentsOfFile:@"example.json"];
 NSError *error = nil;
 YAJLDocument *document = [[YAJLDocument alloc] initWithData:data parserOptions:YAJLParserOptionsNone error:&error];
 // Access root element at document.root
 NSLog(@"Root: %@", document.root);
 [document release];

Example for streaming:

 YAJLDocument *document = [[YAJLDocument alloc] init];
 document.delegate = self;
 
 NSError *error = nil;
 [document parse:chunk1 error:error];
 [document parse:chunk2 error:error];
 
 // You can access root element at document.root
 NSLog(@"Root: %@", document.root);
 [document release];
 
 // Or via the YAJLDocumentDelegate delegate methods
 
 - (void)document:(YAJLDocument *)document didAddDictionary:(NSDictionary *)dict { }
 - (void)document:(YAJLDocument *)document didAddArray:(NSArray *)array { }
 - (void)document:(YAJLDocument *)document didAddObject:(id)object toArray:(NSArray *)array { }
 - (void)document:(YAJLDocument *)document didSetObject:(id)object forKey:(id)key inDictionary:(NSDictionary *)dict { }

Member Function Documentation

- (id) initWithData: (NSData *)  data
parserOptions: (YAJLParserOptions)  parserOptions
capacity: (NSInteger)  capacity
error: (NSError **)  error 

Create document from data.

Parameters:
data Data to parse
parserOptions Parse options

  • YAJLParserOptionsNone: No options
  • YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both / / and //)
  • YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
  • YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
error Error to set on failure
- (id) initWithData: (NSData *)  data
parserOptions: (YAJLParserOptions)  parserOptions
error: (NSError **)  error 

Delegate.

Create document from data.

Parameters:
data Data to parse
parserOptions Parse options

  • YAJLParserOptionsNone: No options
  • YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both / / and //)
  • YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
  • YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
error Error to set on failure
- (id) initWithParserOptions: (YAJLParserOptions)  parserOptions  

Create empty document with parser options.

Parameters:
parserOptions Parse options

  • YAJLParserOptionsNone: No options
  • YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both / / and //)
  • YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
  • YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
- (id) initWithParserOptions: (YAJLParserOptions)  parserOptions
capacity: (NSInteger)  capacity 

Create empty document with parser options.

Parameters:
parserOptions Parse options

  • YAJLParserOptionsNone: No options
  • YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both / / and //)
  • YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
  • YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
- (YAJLParserStatus) parse: (NSData *)  data
error: (NSError **)  error 

Parse data.

Parameters:
data Data to parse
error Out error to set on failure
Returns:
Parser status
  • YAJLParserStatusNone: No status
  • YAJLParserStatusOK: Parsed OK
  • YAJLParserStatusInsufficientData: There was insufficient data
  • YAJLParserStatusError: Parser errored

The documentation for this class was generated from the following files:
 All Classes Functions Properties