Permalink
Browse files

Updating YAJL

  • Loading branch information...
1 parent cb4de69 commit b70246d8d7e795c045fd5aee8718ce4ae69c87c1 @gabriel committed Oct 30, 2009
View
@@ -0,0 +1,3 @@
+build
+*.mode1v3
+*.pbxuser
@@ -9,6 +9,7 @@
#import "JSONPerfTestAppDelegate.h"
#import "JSONTest.h"
+#import "YAJLDocument.h"
@implementation JSONPerfTestAppDelegate
@@ -17,7 +18,9 @@ @implementation JSONPerfTestAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
JSONTest *test = [[JSONTest alloc] init];
- NSInteger count = 100;
+ NSInteger count = 300;
+
+ YAJLDocumentStackCapacity = 20;
[test runWithResourceName:@"twitter_public.json" count:count];
[test runWithResourceName:@"lastfm.json" count:count];
@@ -37,7 +37,7 @@
/*!
Create JSON string from object.
Supported objects include: NSArray, NSDictionary, NSNumber, NSString, NSNull
- To handle JSON manually, implement (id)yajl_JSONObject;
+ To override JSON value to encode (or support custom objects), implement (id)JSON; See YAJLCoding in YAJLGen.h
Otherwise throws YAJLGenInvalidObjectException.
@result JSON String
*/
@@ -46,7 +46,7 @@
/*!
Create JSON string from object.
Supported objects include: NSArray, NSDictionary, NSNumber, NSString, NSNull
- To handle JSON manually, implement (id)yajl_JSONObject;
+ To override JSON value to encode (or support custom objects), implement (id)JSON; See YAJLCoding in YAJLGen.h
Otherwise throws YAJLGenInvalidObjectException.
@param options
@param indentString
@@ -58,20 +58,23 @@
#pragma mark Parsing
/*!
- Parse JSON string.
+ Parse JSON (NSString or NSData or dataUsingEncoding:).
@result JSON object
@throws YAJLParserException If a parse error occured
@throws YAJLParsingUnsupportedException If not NSData or doesn't respond to dataUsingEncoding:
@code
NSString *JSONString = @"{'foo':['bar', true]}";
- [JSONString yajl_JSON];
+ id JSONValue = [JSONString yajl_JSON];
+
+ NSData *JSONData = ...;
+ id JSONValue = [JSONData yajl_JSON];
@endcode
*/
- (id)yajl_JSON;
/*!
- Parse JSON string with out error.
+ Parse JSON (NSString or NSData or dataUsingEncoding:) with out error.
@param error Error to set if we failed to parse
@result JSON object
@throws YAJLParserException If a parse error occured
@@ -87,7 +90,7 @@
- (id)yajl_JSON:(NSError **)error;
/*!
- Parse JSON string with options and out error.
+ Parse JSON (NSString or NSData or dataUsingEncoding:) with options and out error.
@param options Options (see YAJLParserOptions)
@param error Error to set if we failed to parse
@result JSON object
@@ -36,7 +36,7 @@ typedef enum {
YAJLDecoderCurrentTypeDict
} YAJLDecoderCurrentType;
-
+extern NSInteger YAJLDocumentStackCapacity;
@interface YAJLDocument : NSObject <YAJLParserDelegate> {
@@ -54,7 +54,7 @@ typedef enum {
YAJLDecoderCurrentType currentType_;
YAJLParserStatus status_;
-
+
}
@property (readonly, nonatomic) id root; //! Root element
@@ -38,12 +38,30 @@ extern NSString *const YAJLGenInvalidObjectException;
enum {
YAJLGenOptionsNone = 0,
YAJLGenOptionsBeautify = 1 << 0,
+ YAJLGenOptionsIgnoreUnknownTypes = 1 << 1, // Ignore unknown types (will use null value)
+ YAJLGenOptionsIncludeUnsupportedTypes = 1 << 2, // Handle non-JSON types (including NSDate, NSData, NSURL)
};
typedef NSUInteger YAJLGenOptions;
-
+/*!
+ YAJL JSON string generator.
+ Supports the following types:
+ - NSArray
+ - NSDictionary
+ - NSString
+ - NSNumber
+ - NSNull
+
+ We also support the following types (if using YAJLGenOptionsIncludeUnsupportedTypes option),
+ by converting to JSON supported types:
+ - NSDate -> number representing number of milliseconds since (1970) epoch
+ - NSData -> Base64 encoded string
+ - NSURL -> URL (absolute) string
+ */
@interface YAJLGen : NSObject {
yajl_gen gen_;
+
+ YAJLGenOptions genOptions_;
}
- (id)initWithGenOptions:(YAJLGenOptions)genOptions indentString:(NSString *)indentString;
@@ -78,9 +96,9 @@ typedef NSUInteger YAJLGenOptions;
@protocol YAJLCoding <NSObject>
/*!
- Encode to JSON encodable object.
- @result Object such as NSDictionary, NSArray, etc
+ Provide custom and/or encodable object to parse to JSON string.
+ @result Object encodable as JSON such as NSDictionary, NSArray, etc
*/
-- (id)yajl_encodeJSON;
+- (id)JSON;
@end
Binary file not shown.

0 comments on commit b70246d

Please sign in to comment.