Generate JSON string from NSArray, NSDictionary or custom object or parse JSON from NSString or custom object. More...
#import <NSObject+YAJL.h>
Public Member Functions | |
(NSString *) | - yajl_JSONString |
Create JSON string from object. | |
(NSString *) | - yajl_JSONStringWithOptions:indentString: |
Create JSON string from object. | |
(id) | - yajl_JSON |
Parse JSON (NSString or NSData or dataUsingEncoding:). | |
(id) | - yajl_JSON: |
Parse JSON (NSString or NSData or dataUsingEncoding:) with out error. | |
(id) | - yajl_JSONWithOptions:error: |
Parse JSON (NSString or NSData or dataUsingEncoding:) with options and out error. |
Generate JSON string from NSArray, NSDictionary or custom object or parse JSON from NSString or custom object.
Parse JSON:
NSData *JSONData = [NSData dataWithContentsOfFile:@"example.json"]; NSArray *arrayFromData = [JSONData yajl_JSON]; NSString *JSONString = @"[\"Test\"]"; NSArray *arrayFromString = [JSONString yajl_JSON]; // With options and out error NSError *error = nil; NSArray *arrayFromString = [JSONString yajl_JSONWithOptions:YAJLParserOptionsAllowComments error:&error];
Generate JSON:
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
NSString *JSONString = [dict yajl_JSONString];
// Beautified with custon indent string
NSArray *array = [NSArray arrayWithObjects:@"value1", @"value2", nil];
NSString *JSONString = [dict yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "];
- (id) yajl_JSON |
Parse JSON (NSString or NSData or dataUsingEncoding:).
YAJLParserException | If a parse error occured | |
YAJLParsingUnsupportedException | If not NSData or doesn't respond to dataUsingEncoding: |
NSString *JSONString = @"{'foo':['bar', true]}"; id JSONValue = [JSONString yajl_JSON]; NSData *JSONData = ...; id JSONValue = [JSONData yajl_JSON];
- (id) yajl_JSON: | (NSError **) | error |
Parse JSON (NSString or NSData or dataUsingEncoding:) with out error.
If an error occurs, the returned object will be the current state of the object when the error occurred.
error | Error to set if we failed to parse |
YAJLParserException | If a parse error occured | |
YAJLParsingUnsupportedException | If not NSData or doesn't respond to dataUsingEncoding: |
NSString *JSONString = @"{'foo':['bar', true]}"; NSError *error = nil; [JSONString yajl_JSON:error]; if (error) ...;
- (NSString *) yajl_JSONString |
Create JSON string from object.
Supported objects include: NSArray, NSDictionary, NSNumber, NSString, NSNull To override JSON value to encode (or support custom objects), implement (id)JSON; See YAJLCoding in YAJLGen.h
YAJLGenInvalidObjectException | If object is invalid |
- (NSString *) yajl_JSONStringWithOptions: | (YAJLGenOptions) | options | ||
indentString: | (NSString *) | indentString | ||
Create JSON string from object.
Supported objects include: NSArray, NSDictionary, NSNumber, NSString, NSNull To override JSON value to encode (or support custom objects), implement (id)JSON; See YAJLCoding in YAJLGen.h
YAJLGenInvalidObjectException | If object is invalid |
options |
| |
indentString |
- (id) yajl_JSONWithOptions: | (YAJLParserOptions) | options | ||
error: | (NSError **) | error | ||
Parse JSON (NSString or NSData or dataUsingEncoding:) with options and out error.
If an error occurs, the returned object will be the current state of the object when the error occurred.
options | Parse options
| |
error | Error to set if we failed to parse |
YAJLParserException | If a parse error occured | |
YAJLParsingUnsupportedException | If not NSData or doesn't respond to dataUsingEncoding: |
NSString *JSONString = @"{'foo':['bar', true]} // comment"; NSError *error = nil; [JSONString yajl_JSONWithOptions:YAJLParserOptionsAllowComments error:error]; if (error) ...;