YAJLDocument Class Reference

#import <YAJLDocument.h>

Inheritance diagram for YAJLDocument:
NSObject <YAJLParserDelegate>

List of all members.

Public Member Functions

(id) - initWithData:parserOptions:error:
 Delegate.
(id) - initWithParserOptions:
(YAJLParserStatus) - parse:error:
(void) - _pop
(void) - _popKey

Protected Attributes

id root_
YAJLParserparser_
id< YAJLDocumentDelegatedelegate_
__weak NSMutableDictionarydict_
__weak NSMutableArrayarray_
__weak NSStringkey_
NSMutableArraystack_
NSMutableArraykeyStack_
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
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
- (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:
  • extThree20JSON/Vendors/YAJL/YAJLDocument.h
  • extThree20JSON/Vendors/YAJL/YAJLDocument.m
blog comments powered by Disqus