Find file
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (64 sloc) 2.51 KB
// TouchDB
// Created by Jens Alfke on 2/27/12.
// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
#import <Foundation/Foundation.h>
// Conditional compilation for JSONKit and/or NSJSONSerialization.
// If the app supports OS versions prior to NSJSONSerialization, we'll use JSONKit.
#elif defined(TARGET_OS_MAC)
#elif defined(GNUSTEP)
#define USE_NSJSON 1
#define USE_NSJSON 0
/** Identical to the corresponding NSJSON option flags. */
enum {
TDJSONReadingMutableContainers = (1UL << 0),
TDJSONReadingMutableLeaves = (1UL << 1),
TDJSONReadingAllowFragments = (1UL << 2)
typedef NSUInteger TDJSONReadingOptions;
/** Identical to the corresponding NSJSON option flags. */
enum {
TDJSONWritingPrettyPrinted = (1UL << 0),
TDJSONWritingAllowFragments = (1UL << 23) // This one I made up
typedef NSUInteger TDJSONWritingOptions;
@interface TDJSON : NSJSONSerialization
@interface TDJSON : NSObject
+ (NSData *)dataWithJSONObject:(id)obj
error:(NSError **)error;
+ (id)JSONObjectWithData:(NSData *)data
error:(NSError **)error;
#endif // USE_NSJSON
@interface TDJSON (Extensions)
/** Same as -dataWithJSONObject... but returns an NSString. */
+ (NSString*) stringWithJSONObject:(id)obj
error:(NSError **)error;
/** Given valid JSON data representing a dictionary, inserts the contents of the given NSDictionary into it and returns the resulting JSON data.
This does not parse or regenerate the JSON, so it's quite fast.
But it will generate invalid JSON if the input JSON begins or ends with whitespace, or if the dictionary contains any keys that are already in the original JSON. */
+ (NSData*) appendDictionary: (NSDictionary*)dict
toJSONDictionaryData: (NSData*)json;
/** Wrapper for an NSArray of JSON data, that avoids having to parse the data if it's not used.
NSData objects in the array will be parsed into native objects before being returned to the caller from -objectAtIndex. */
@interface TDLazyArrayOfJSON : NSArray
NSMutableArray* _array;
- (id) initWithArray: (NSMutableArray*)array;