Skip to content

Commit

Permalink
Merge pull request facebookarchive#597 from aporat/extThree20JSON_Update
Browse files Browse the repository at this point in the history
[extJSON] updated JSON library to version 3.0
  • Loading branch information
jwang committed Jul 11, 2011
2 parents 06e0189 + b6f5f08 commit 3cd5869
Show file tree
Hide file tree
Showing 23 changed files with 3,001 additions and 753 deletions.
63 changes: 61 additions & 2 deletions src/extThree20JSON/Vendors/JSON/Changes.markdown 100755 → 100644
@@ -1,11 +1,70 @@
# JSON Framework Changes
# JSON Framework Changes

## Version 3.0beta2 (TBD)

## Changes
* [Issue 46][#46]: Stream Parser delegate methods are now optional.

### Bug Fixes
* [Issue 42][#42]: Fix bug in handling of Unicode Surrogate Pairs.
* [Issue 48][#48]: Increase precision when writing floating-point numbers so NSTimeInterval instances since epoch can be represented fully.

[#42]: http://github.com/stig/json-framework/issues/#issue/42
[#46]: http://github.com/stig/json-framework/issues/#issue/46
[#48]: http://github.com/stig/json-framework/issues/#issue/48

## Version 3.0beta1 (January 30th, 2011)

### Bug Fixes
* [Issue 36][#36]: Fix bug in build script that caused it to break if $SRCROOT has spaces.

[#36]: http://github.com/stig/json-framework/issues/#issue/36

### Changes

* Remove the hacky dataToHere method in favour of just exposing the internal NSMutableData buffer.
* Added a minimal Mac example project showing how to link to an external JSON framework rather than copying the sources into your project.

## Version 3.0alpha3 (January 2nd, 2011)

* Added documentation to the TwitterStream sample project.
* Fixed a few warnings, bugs & a memory leak reported by Andy Warwick.

## Version 3.0alpha2 (December 28th, 2010)

### Changes

* Minor changes to formatting when the HumanReadable flag is set. Empty arrays and objects are no longer special-cased to appear on a single line. The separator between key and value in an object has changed to ': ' rather than ' : '.
* [Issue 25][#25]: Simplified error handling.

### New Features

* [Issue 16][#16]: Added support for parsing a UTF8 data stream. This means you can start parsing huge documents before it's all downloaded. Supports skipping the outer-most layer of huge arrays/objects or parsing multiple whitespace-separated completed documents.
* [Issue 12][#12]: Added support for writing JSON to a data stream. This means you can write huge JSON documents to disk, or an HTTP destination, without having to hold the entire structure in memory. You can even generate it as you go, and just stream snapshots to an external process.
* [Issue 18][#18] & [27][#27]: Re-orient API to be NSData-based. The NSString-oriented API methods now delegates to this.

### Enhancements

* [Issue 9][#9]: Improve performance of the SBJsonWriter. This implementation is nearly twice as fast as 2.3.x on Sam Soffes' [benchmarks][bench].
* [Issue 30][#30]: Added *TwitterStream* example project showing how to interact with Twitter's multi-document stream. (See `Examples/TwitterStream` in the distribution.)

[bench]: http://github.com/samsoffes/json-benchmarks
[#9]: http://github.com/stig/json-framework/issues/#issue/9
[#12]: http://github.com/stig/json-framework/issues/#issue/12
[#16]: http://github.com/stig/json-framework/issues/#issue/16
[#18]: http://github.com/stig/json-framework/issues/#issue/18
[#27]: http://github.com/stig/json-framework/issues/#issue/27
[#30]: http://github.com/stig/json-framework/issues/#issue/30
[#25]: http://github.com/stig/json-framework/issues/#issue/25

## Version 2.3.1 (September 25th, 2010)

### Changes

* Move to host releases on Github rather than Google code.
* Renamed .md files to .markdown.
* Removed bench target--use [Sam Soffes's benchmarks][json-benchmark] instead.
* Releases are no longer a munged form of the source tree, but identical to the tagged source.

[json-benchmark]: http://github.com/samsoffes/json-benchmark

Expand All @@ -29,7 +88,7 @@
### Changes

* **Parsing performance improvements.**
[Issue 56][issue-56]: Dewvinci & Tobias Hoehmann came up with a patch to improve parsing of short JSON texts with lots of numbers by over 60%.
[Issue 56][issue-56]: Dewvinci & Tobias Höhmann came up with a patch to improve parsing of short JSON texts with lots of numbers by over 60%.
* **Refactored tests to be more data-driven.**
This should make the source leaner and easier to maintain.
* **Removed problematic SDK**
Expand Down
14 changes: 14 additions & 0 deletions src/extThree20JSON/Vendors/JSON/Credits.markdown 100755 → 100644
Expand Up @@ -45,3 +45,17 @@ Reported bug in SBJsonWriter's handling of NaN, Infinity and -Infinity.

## jinksys
Reported bug with header inclusion of framework.

## Lloyd Hilaiel
For his work on [YAJL][yajl] (Yet Another JSON Library)

[yajl]: http://github.com/lloyd/yajl

## Gabriel Handford

For his work on [YAJL-ObjC][yajl-objc].

[yajl-objc]: http://github.com/gabriel/yajl-objc

## Andy Warwick
Reported several build-issues that I didn't catch.
52 changes: 28 additions & 24 deletions src/extThree20JSON/Vendors/JSON/JSON.h
@@ -1,20 +1,20 @@
/*
Copyright (C) 2009-2010 Stig Brautaset. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -28,38 +28,42 @@
*/

/**
A strict JSON parser and generator for Objective-C
@mainpage A strict JSON parser and generator for Objective-C
JSON (JavaScript Object Notation) is a lightweight data-interchange
format. This framework provides two apis for parsing and generating
JSON. One standard object-based and a higher level api consisting of
categories added to existing Objective-C classes.
This framework does its best to be as strict as possible, both in what it accepts and what it generates. For example, it does not support trailing commas in arrays or objects. Nor does it support embedded comments, or anything else not in the JSON specification. This is considered a feature.
This framework does its best to be as strict as possible, both in what it accepts and what it generates. For example, it does not support trailing commas in arrays or objects. Nor does it support embedded comments, or anything else not in the JSON specification. This is considered a feature.
@section Links
@li <a href="http://stig.github.com/json-framework">Project home page</a>.
@li Online version of the <a href="http://stig.github.com/json-framework/api">API documentation</a>.
*/
@li Online version of the <a href="http://stig.github.com/json-framework/api">API documentation</a>.
*/


// This setting of 1 is best if you copy the source into your project.
// This setting of 1 is best if you copy the source into your project.
// The build transforms the 1 to a 0 when building the framework and static lib.

#if 1

#import "extThree20JSON/SBJsonParser.h"
#import "extThree20JSON/SBJsonWriter.h"
#import "extThree20JSON/NSObject+SBJSON.h"
#import "extThree20JSON/NSString+SBJSON.h"
#import "extThree20JSON/SBJsonStreamWriter.h"
#import "extThree20JSON/SBJsonStreamParser.h"
#import "extThree20JSON/SBJsonStreamParserAdapter.h"
#import "extThree20JSON/NSObject+JSON.h"

#else
#import <JSON/SBJsonParser.h>
#import <JSON/SBJsonWriter.h>
#import <JSON/NSObject+SBJSON.h>
#import <JSON/NSString+SBJSON.h>
#import <JSON/SBJsonStreamParser.h>
#import <JSON/SBJsonStreamParserAdapter.h>
#import <JSON/SBJsonStreamWriter.h>
#import <JSON/NSObject+JSON.h>
#endif
61 changes: 61 additions & 0 deletions src/extThree20JSON/Vendors/JSON/NSObject+JSON.h
@@ -0,0 +1,61 @@
/*
Copyright (C) 2009 Stig Brautaset. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#import <Foundation/Foundation.h>

#pragma mark JSON Writing

/// Adds JSON generation to NSArray
@interface NSArray (NSArray_SBJsonWriting)

/// Returns a string containing the receiver encoded in JSON.
- (NSString *)JSONRepresentation;

@end


/// Adds JSON generation to NSArray
@interface NSDictionary (NSDictionary_SBJsonWriting)

/// Returns a string containing the receiver encoded in JSON.
- (NSString *)JSONRepresentation;

@end

#pragma mark JSON Parsing

/// Adds JSON parsing methods to NSString
@interface NSString (NSString_SBJsonParsing)

/// Returns the NSDictionary or NSArray represented by the receiver's JSON representation, or nil on error
- (id)JSONValue;

@end


60 changes: 60 additions & 0 deletions src/extThree20JSON/Vendors/JSON/NSObject+JSON.m
@@ -0,0 +1,60 @@
/*
Copyright (C) 2009 Stig Brautaset. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#import "NSObject+JSON.h"
#import "SBJsonWriter.h"
#import "SBJsonParser.h"

@implementation NSObject (NSObject_SBJsonWriting)

- (NSString *)JSONRepresentation {
SBJsonWriter *jsonWriter = [SBJsonWriter new];
NSString *json = [jsonWriter stringWithObject:self];
if (!json)
NSLog(@"-JSONRepresentation failed. Error is: %@", jsonWriter.error);
[jsonWriter release];
return json;
}

@end



@implementation NSString (NSString_SBJsonParsing)

- (id)JSONValue {
SBJsonParser *jsonParser = [SBJsonParser new];
id repr = [jsonParser objectWithString:self];
if (!repr)
NSLog(@"-JSONValue failed. Error is: %@", jsonParser.error);
[jsonParser release];
return repr;
}

@end
Empty file modified src/extThree20JSON/Vendors/JSON/Readme.markdown 100755 → 100644
Empty file.

0 comments on commit 3cd5869

Please sign in to comment.