├── .gitignore ├── README.md ├── jsonrpc.framework ├── Headers ├── Versions │ ├── A │ │ ├── Headers │ │ │ ├── JSONKit.h │ │ │ ├── JSONRPCClient+Invoke.h │ │ │ ├── JSONRPCClient+Multicall.h │ │ │ ├── JSONRPCClient+Notification.h │ │ │ ├── JSONRPCClient.h │ │ │ ├── RPCError.h │ │ │ ├── RPCRequest.h │ │ │ ├── RPCResponse.h │ │ │ └── jsonrpc.h │ │ └── jsonrpc │ └── Current └── jsonrpc ├── jsonrpc ├── jsonrpc-Prefix.pch ├── jsonrpc.h └── jsonrpc.m ├── objc-JSONRpc.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── rasmus.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── rasmus.xcuserdatad │ ├── xcdebugger │ └── Breakpoints.xcbkptlist │ └── xcschemes │ ├── objc-JSONRpc.xcscheme │ └── xcschememanagement.plist └── objc-JSONRpc ├── AppDelegate.h ├── AppDelegate.m ├── RPC Client ├── Client │ ├── JSONRPCClient+Invoke.h │ ├── JSONRPCClient+Invoke.m │ ├── JSONRPCClient+Multicall.h │ ├── JSONRPCClient+Multicall.m │ ├── JSONRPCClient+Notification.h │ ├── JSONRPCClient+Notification.m │ ├── JSONRPCClient.h │ └── JSONRPCClient.m ├── Helpers │ └── JSONKit │ │ ├── CHANGELOG.md │ │ ├── JSONKit.h │ │ ├── JSONKit.m │ │ └── README.md └── Models │ ├── RPCError.h │ ├── RPCError.m │ ├── RPCRequest.h │ ├── RPCRequest.m │ ├── RPCResponse.h │ └── RPCResponse.m ├── en.lproj └── InfoPlist.strings ├── main.m ├── objc-JSONRpc-Info.plist └── objc-JSONRpc-Prefix.pch /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | objc-JSONRpc 2 | ============ 3 | 4 | An objective-c 2.0 JSON RPC Client. Currently only supports json rpc version 2.0. 5 | 6 | #### Todo: 7 | * Support ARC (might be a problem since JSONKit does not support ARC at the moment) 8 | 9 | #### Supports: 10 | * Single calls 11 | * Notifications 12 | * Multicall 13 | 14 | How-To 15 | ------------------------- 16 | 17 | Follow these simple steps: 18 | 19 | * Add RPC Client folder from within this project to your project 20 | * #import "JSONRPCClient+Invoke.h" 21 | * Start doing calls 22 | 23 | NB: Remove JSONKit either from this client or your project if you already uses it to avoid symbol conflicts. 24 | 25 | ```objective-c 26 | JSONRPCClient *rpc = [[JSONRPCClient alloc] initWithServiceEndpoint:@"... URL to your endpoint"]; 27 | [rpc invoke:@"your method" params:nil onCompleted:^(RPCResponse *response) { 28 | 29 | NSLog(@"Respone: %@", response); 30 | NSLog(@"Error: %@", response.error); 31 | NSLog(@"Result: %@", response.result); 32 | 33 | }]; 34 | [rpc release]; 35 | ``` 36 | 37 | #### Invoking methods/requests 38 | 39 | These methods is public when you have an instance of the RPC Client. 40 | 41 | ```objective-c 42 | /** 43 | * Invokes a RPCRequest against the end point 44 | * 45 | * @param RPCRequest reqeust The request to invoke 46 | * @param RPCCompletedCallback A callback method to invoke when request is done (or any error accours) 47 | * @return NSString The used request id. Can be used to match callback's if neccesary 48 | */ 49 | - (NSString *) invoke:(RPCRequest*) request onCompleted:(RPCCompletedCallback)callback; 50 | 51 | /** 52 | * Invokes a method against the end point 53 | * 54 | * @param NSString method The method to invoke 55 | * @param id Either named or un-named parameter list (or nil) 56 | * @param RPCCompletedCallback A callback method to invoke when request is done (or any error accours) 57 | * @return NSString The used request id. Can be used to match callback's if neccesary 58 | */ 59 | - (NSString *) invoke:(NSString*) method params:(id) params onCompleted:(RPCCompletedCallback)callback; 60 | 61 | /** 62 | * Invokes a method against endpoint providing a way to define both a success callback and a failure callback. 63 | * 64 | * @param NSString method The method to invoke 65 | * @param id Either named or un-named parameter list (or nil) 66 | * @param RPCSuccessCallback A callback method to invoke when request finishes successfull 67 | * @param RPCFailedCallback A callback method to invoke when request finishes with an error 68 | * @return NSString The used request id. Can be used to match callback's if neccesary 69 | */ 70 | - (NSString *) invoke:(NSString*) method params:(id) params onSuccess:(RPCSuccessCallback)successCallback onFailure:(RPCFailedCallback)failedCallback; 71 | 72 | ``` 73 | 74 | #### Invoking multicall 75 | 76 | Multicalls is a great way to send multiple requests as once. 77 | 78 | ````objective-c 79 | /** 80 | * Sends batch of RPCRequest objects to the server. The call to this method must be nil terminated. 81 | * 82 | * @param RPCRequest request The first request to send 83 | * @param ...A list of RPCRequest objects to send, must be nil terminated 84 | */ 85 | - (void) batch:(RPCRequest*) request, ...; 86 | ```` 87 | 88 | ##### Example of a multicall 89 | 90 | ````objective-c 91 | JSONRPCClient *rpc = [[JSONRPCClient alloc] initWithServiceEndpoint:@"..."]; 92 | 93 | RPCRequest *doWork = [RPCRequest requestWithMethod:@"doWork" params:nil]; 94 | doWork.callback = ^(RPCResponse *response) 95 | { 96 | // Handle response here 97 | }; 98 | 99 | RPCRequest *doSomeOtherWork = [RPCRequest requestWithMethod:@"doSomeOtherWork" params:nil]; 100 | doSomeOtherWork.callback = ^(RPCResponse *response) 101 | { 102 | // Handle response here 103 | }; 104 | 105 | [rpc batch:doWork, doSomeOtherWork, nil]; 106 | [rpc release]; 107 | ```` 108 | 109 | #### Invoking notifications 110 | 111 | You need to ````#import "JSONRPCClient+Notification.h"```` to add notification support to the JSONRPCClient. These methods are added to the class as a category. 112 | 113 | ````objective-c 114 | 115 | /** 116 | * Sends a notification to json rpc server. 117 | * 118 | * @param NSString method Method to call 119 | */ 120 | - (void) notify:(NSString *)method; 121 | 122 | /** 123 | * Sends a notification to json rpc server. 124 | * 125 | * @param NSString method Method to call 126 | * @param id Either named or un-named parameter list (or nil) 127 | */ 128 | - (void) notify:(NSString *)method params:(id)params; 129 | ```` 130 | 131 | ##### Example of a notification 132 | 133 | This could be used to keep a session alive on a webserver 134 | 135 | ````objective-c 136 | JSONRPCClient *rpc = [[JSONRPCClient alloc] initWithServiceEndpoint:@"..."]; 137 | [rpc notify:@"keepAlive"]; 138 | [rpc release]; 139 | ```` 140 | 141 | License 142 | ------------------------- 143 | Licensed under Attribution-ShareAlike 4.0 International 144 | 145 | Read more: https://creativecommons.org/licenses/by-sa/4.0/ 146 | -------------------------------------------------------------------------------- /jsonrpc.framework/Headers: -------------------------------------------------------------------------------- 1 | Versions/Current/Headers -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/JSONKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONKit.h 3 | // http://github.com/johnezang/JSONKit 4 | // Dual licensed under either the terms of the BSD License, or alternatively 5 | // under the terms of the Apache License, Version 2.0, as specified below. 6 | // 7 | 8 | /* 9 | Copyright (c) 2011, John Engelhart 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright 17 | notice, this list of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright 20 | notice, this list of conditions and the following disclaimer in the 21 | documentation and/or other materials provided with the distribution. 22 | 23 | * Neither the name of the Zang Industries nor the names of its 24 | contributors may be used to endorse or promote products derived from 25 | this software without specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 33 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* 41 | Copyright 2011 John Engelhart 42 | 43 | Licensed under the Apache License, Version 2.0 (the "License"); 44 | you may not use this file except in compliance with the License. 45 | You may obtain a copy of the License at 46 | 47 | http://www.apache.org/licenses/LICENSE-2.0 48 | 49 | Unless required by applicable law or agreed to in writing, software 50 | distributed under the License is distributed on an "AS IS" BASIS, 51 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 | See the License for the specific language governing permissions and 53 | limitations under the License. 54 | */ 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | #ifdef __OBJC__ 63 | #import 64 | #import 65 | #import 66 | #import 67 | #import 68 | #import 69 | #endif // __OBJC__ 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | 76 | // For Mac OS X < 10.5. 77 | #ifndef NSINTEGER_DEFINED 78 | #define NSINTEGER_DEFINED 79 | #if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) 80 | typedef long NSInteger; 81 | typedef unsigned long NSUInteger; 82 | #define NSIntegerMin LONG_MIN 83 | #define NSIntegerMax LONG_MAX 84 | #define NSUIntegerMax ULONG_MAX 85 | #else // defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) 86 | typedef int NSInteger; 87 | typedef unsigned int NSUInteger; 88 | #define NSIntegerMin INT_MIN 89 | #define NSIntegerMax INT_MAX 90 | #define NSUIntegerMax UINT_MAX 91 | #endif // defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) 92 | #endif // NSINTEGER_DEFINED 93 | 94 | 95 | #ifndef _JSONKIT_H_ 96 | #define _JSONKIT_H_ 97 | 98 | #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__APPLE_CC__) && (__APPLE_CC__ >= 5465) 99 | #define JK_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) 100 | #else 101 | #define JK_DEPRECATED_ATTRIBUTE 102 | #endif 103 | 104 | #define JSONKIT_VERSION_MAJOR 1 105 | #define JSONKIT_VERSION_MINOR 4 106 | 107 | typedef NSUInteger JKFlags; 108 | 109 | /* 110 | JKParseOptionComments : Allow C style // and /_* ... *_/ (without a _, obviously) comments in JSON. 111 | JKParseOptionUnicodeNewlines : Allow Unicode recommended (?:\r\n|[\n\v\f\r\x85\p{Zl}\p{Zp}]) newlines. 112 | JKParseOptionLooseUnicode : Normally the decoder will stop with an error at any malformed Unicode. 113 | This option allows JSON with malformed Unicode to be parsed without reporting an error. 114 | Any malformed Unicode is replaced with \uFFFD, or "REPLACEMENT CHARACTER". 115 | */ 116 | 117 | enum { 118 | JKParseOptionNone = 0, 119 | JKParseOptionStrict = 0, 120 | JKParseOptionComments = (1 << 0), 121 | JKParseOptionUnicodeNewlines = (1 << 1), 122 | JKParseOptionLooseUnicode = (1 << 2), 123 | JKParseOptionPermitTextAfterValidJSON = (1 << 3), 124 | JKParseOptionValidFlags = (JKParseOptionComments | JKParseOptionUnicodeNewlines | JKParseOptionLooseUnicode | JKParseOptionPermitTextAfterValidJSON), 125 | }; 126 | typedef JKFlags JKParseOptionFlags; 127 | 128 | enum { 129 | JKSerializeOptionNone = 0, 130 | JKSerializeOptionPretty = (1 << 0), 131 | JKSerializeOptionEscapeUnicode = (1 << 1), 132 | JKSerializeOptionEscapeForwardSlashes = (1 << 4), 133 | JKSerializeOptionValidFlags = (JKSerializeOptionPretty | JKSerializeOptionEscapeUnicode | JKSerializeOptionEscapeForwardSlashes), 134 | }; 135 | typedef JKFlags JKSerializeOptionFlags; 136 | 137 | #ifdef __OBJC__ 138 | 139 | typedef struct JKParseState JKParseState; // Opaque internal, private type. 140 | 141 | // As a general rule of thumb, if you use a method that doesn't accept a JKParseOptionFlags argument, it defaults to JKParseOptionStrict 142 | 143 | @interface JSONDecoder : NSObject { 144 | JKParseState *parseState; 145 | } 146 | + (id)decoder; 147 | + (id)decoderWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 148 | - (id)initWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 149 | - (void)clearCache; 150 | 151 | // The parse... methods were deprecated in v1.4 in favor of the v1.4 objectWith... methods. 152 | - (id)parseUTF8String:(const unsigned char *)string length:(size_t)length JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithUTF8String:length: instead. 153 | - (id)parseUTF8String:(const unsigned char *)string length:(size_t)length error:(NSError **)error JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithUTF8String:length:error: instead. 154 | // The NSData MUST be UTF8 encoded JSON. 155 | - (id)parseJSONData:(NSData *)jsonData JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithData: instead. 156 | - (id)parseJSONData:(NSData *)jsonData error:(NSError **)error JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithData:error: instead. 157 | 158 | // Methods that return immutable collection objects. 159 | - (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length; 160 | - (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error; 161 | // The NSData MUST be UTF8 encoded JSON. 162 | - (id)objectWithData:(NSData *)jsonData; 163 | - (id)objectWithData:(NSData *)jsonData error:(NSError **)error; 164 | 165 | // Methods that return mutable collection objects. 166 | - (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length; 167 | - (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error; 168 | // The NSData MUST be UTF8 encoded JSON. 169 | - (id)mutableObjectWithData:(NSData *)jsonData; 170 | - (id)mutableObjectWithData:(NSData *)jsonData error:(NSError **)error; 171 | 172 | @end 173 | 174 | //////////// 175 | #pragma mark Deserializing methods 176 | //////////// 177 | 178 | @interface NSString (JSONKitDeserializing) 179 | - (id)objectFromJSONString; 180 | - (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 181 | - (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 182 | - (id)mutableObjectFromJSONString; 183 | - (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 184 | - (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 185 | @end 186 | 187 | @interface NSData (JSONKitDeserializing) 188 | // The NSData MUST be UTF8 encoded JSON. 189 | - (id)objectFromJSONData; 190 | - (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 191 | - (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 192 | - (id)mutableObjectFromJSONData; 193 | - (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 194 | - (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 195 | @end 196 | 197 | //////////// 198 | #pragma mark Serializing methods 199 | //////////// 200 | 201 | @interface NSString (JSONKitSerializing) 202 | // Convenience methods for those that need to serialize the receiving NSString (i.e., instead of having to serialize a NSArray with a single NSString, you can "serialize to JSON" just the NSString). 203 | // Normally, a string that is serialized to JSON has quotation marks surrounding it, which you may or may not want when serializing a single string, and can be controlled with includeQuotes: 204 | // includeQuotes:YES `a "test"...` -> `"a \"test\"..."` 205 | // includeQuotes:NO `a "test"...` -> `a \"test\"...` 206 | - (NSData *)JSONData; // Invokes JSONDataWithOptions:JKSerializeOptionNone includeQuotes:YES 207 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error; 208 | - (NSString *)JSONString; // Invokes JSONStringWithOptions:JKSerializeOptionNone includeQuotes:YES 209 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error; 210 | @end 211 | 212 | @interface NSArray (JSONKitSerializing) 213 | - (NSData *)JSONData; 214 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 215 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 216 | - (NSString *)JSONString; 217 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 218 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 219 | @end 220 | 221 | @interface NSDictionary (JSONKitSerializing) 222 | - (NSData *)JSONData; 223 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 224 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 225 | - (NSString *)JSONString; 226 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 227 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 228 | @end 229 | 230 | #ifdef __BLOCKS__ 231 | 232 | @interface NSArray (JSONKitSerializingBlockAdditions) 233 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 234 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 235 | @end 236 | 237 | @interface NSDictionary (JSONKitSerializingBlockAdditions) 238 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 239 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 240 | @end 241 | 242 | #endif 243 | 244 | 245 | #endif // __OBJC__ 246 | 247 | #endif // _JSONKIT_H_ 248 | 249 | #ifdef __cplusplus 250 | } // extern "C" 251 | #endif 252 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/JSONRPCClient+Invoke.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Invoke.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 9/16/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | 11 | // Few other callback types (default RPCCompletedCallback is defined inside BaseRPCClient.h) 12 | typedef void (^RPCSuccessCallback)(RPCResponse *response); 13 | typedef void (^RPCFailedCallback)(RPCError *error); 14 | 15 | /** 16 | * Invoking 17 | * 18 | * - Adds invoking of methods on the remote server through the jsonrpcclient class 19 | */ 20 | @interface JSONRPCClient (Invoke) 21 | 22 | /** 23 | * Invokes a RPCRequest against the end point. 24 | * 25 | * @param RPCRequest reqeust The request to invoke 26 | * @return NSString The used request id. Can be used to match callback's if neccesary 27 | */ 28 | - (NSString *) invoke:(RPCRequest*) request; 29 | 30 | /** 31 | * Invokes a method against the end point. This method actually generates an RPCRequest object and calls invoke:request 32 | * 33 | * @param NSString method The method to invoke 34 | * @param id Either named or un-named parameter list (or nil) 35 | * @param RPCCompletedCallback A callback method to invoke when request is done (or any error accours) 36 | * @return NSString The used request id. Can be used to match callback's if neccesary 37 | */ 38 | - (NSString *) invoke:(NSString*) method params:(id) params onCompleted:(RPCRequestCallback)callback; 39 | 40 | /** 41 | * Invokes a method against endpoint providing a way to define both a success callback and a failure callback. 42 | * 43 | * This method simply wraps invoke:method:params:onCompleted 44 | * 45 | * @param NSString method The method to invoke 46 | * @param id Either named or un-named parameter list (or nil) 47 | * @param RPCSuccessCallback A callback method to invoke when request finishes successfull 48 | * @param RPCFailedCallback A callback method to invoke when request finishes with an error 49 | * @return NSString The used request id. Can be used to match callback's if neccesary 50 | */ 51 | - (NSString *) invoke:(NSString*) method params:(id) params onSuccess:(RPCSuccessCallback)successCallback onFailure:(RPCFailedCallback)failedCallback; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/JSONRPCClient+Multicall.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Invoke.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/29/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | 11 | /** 12 | * Multicall 13 | * 14 | * - Adds invoking of multicalls to the remote server through the jsonrpcclient class 15 | */ 16 | @interface JSONRPCClient (Multicall) 17 | 18 | /** 19 | * Sends batch of RPCRequest objects to the server. The call to this method must be nil terminated. 20 | * 21 | * @param RPCRequest request The first request to send 22 | * @param ...A list of RPCRequest objects to send, must be nil terminated 23 | */ 24 | - (void) batch:(RPCRequest*) request, ...; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/JSONRPCClient+Notification.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Notifications.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 03/09/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | 11 | /** 12 | * Notificiation 13 | * 14 | * - Implements a way to use notifications in json rpc client. 15 | * 16 | * Its important to understand that notifications does not * allow using callbacks and therefor you 17 | * need to make sure you call your server in the right way since there is no telling if * your notification was 18 | * successfull or not. 19 | */ 20 | @interface JSONRPCClient (Notification) 21 | 22 | /** 23 | * Sends a notification to json rpc server. 24 | * 25 | * @param NSString method Method to call 26 | */ 27 | - (void) notify:(NSString *)method; 28 | 29 | /** 30 | * Sends a notification to json rpc server. 31 | * 32 | * @param NSString method Method to call 33 | * @param id Either named or un-named parameter list (or nil) 34 | */ 35 | - (void) notify:(NSString *)method params:(id)params; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/JSONRPCClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCJSONClient.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | // Hack to allow categories to be used withing a static library/framework 10 | #define STATIC_CATEGORY(name) @interface STATIC_CATEGORY##name @end @implementation STATIC_CATEGORY##name @end 11 | 12 | #import 13 | #import "RPCRequest.h" 14 | #import "RPCError.h" 15 | #import "RPCResponse.h" 16 | 17 | /** 18 | * JSONRPCClient 19 | * 20 | * Provides means to communicate with the RPC server and is responsible of serializing/parsing requests 21 | * that is send and recieved. 22 | * 23 | * Handles calling of RPCRequest callbacks and generates RPCResponse/RPCError objects. 24 | * 25 | * Retains requests while they are completing and manages calling of callback's. 26 | */ 27 | @interface JSONRPCClient : NSObject 28 | 29 | #pragma mark - Properties - 30 | 31 | /** 32 | * What service endpoint we talk to. Just a simple string containing an URL. 33 | * It will later be converted to an NSURL Object, so anything that NSURL Supports 34 | * is valid- 35 | */ 36 | @property (nonatomic, retain) NSString *serviceEndpoint; 37 | 38 | /** 39 | * All the reqeusts that is being executed is added to this statck 40 | */ 41 | @property (nonatomic, retain) NSMutableDictionary *requests; 42 | 43 | /** 44 | * All returned data from the server is saved into this dictionary for later processing 45 | */ 46 | @property (nonatomic, retain) NSMutableDictionary *requestData; 47 | 48 | #pragma mark - Methods 49 | 50 | /** 51 | * Inits RPC Client with a specific end point. 52 | * 53 | * @param NSString endpoint Should be some kind of standard URL 54 | * @return RPCClient 55 | */ 56 | - (id) initWithServiceEndpoint:(NSString*) endpoint; 57 | 58 | /** 59 | * Post requests syncronous 60 | * 61 | * Posts requests to the server via HTTP post. Always uses multicall to simplify handling 62 | * of responses. 63 | * 64 | * If the server your talking with do not understand multicall then you have a problem. 65 | */ 66 | - (void) postRequests:(NSArray*)requests; 67 | 68 | /** 69 | * Post Requests Async 70 | * 71 | * Posts requests to the server via HTTP post. Always uses multicall to simplify handling 72 | * of responses. 73 | * 74 | * If the server your talking with do not understand multicall then you have a problem. 75 | * 76 | */ 77 | - (void) postRequests:(NSArray *)requests async:(BOOL)async; 78 | 79 | /** 80 | * Posts a single single request 81 | * 82 | */ 83 | - (void) postRequest:(RPCRequest*)request async:(BOOL)async; 84 | 85 | /** 86 | * Sends a synchronous request that returns the response object 87 | * instead of using callbacks 88 | */ 89 | - (RPCResponse*) sendSynchronousRequest:(RPCRequest*)request; 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/RPCError.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCError.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | // Reserved rpc errors 13 | typedef enum { 14 | RPCParseError = -32700, 15 | RPCInvalidRequest = -32600, 16 | RPCMethodNotFound = -32601, 17 | RPCInvalidParams = -32602, 18 | RPCInternalError = -32603, 19 | RPCServerError = 32000, 20 | RPCNetworkError = 32001 21 | } RPCErrorCode; 22 | 23 | /** 24 | * RPCError. 25 | * 26 | * Simple object containing information about errors. Erros can be generated serverside or internally within this client. 27 | * See RPCErrorCode above for the most common errors. 28 | */ 29 | @interface RPCError : NSObject 30 | 31 | #pragma mark - Properties - 32 | 33 | /** 34 | * RPC Error code. Error code that you can match against the RPCErrorCode enum above. 35 | * 36 | * Server can generate other errors aswell, for a description of server errors you need to contact server 37 | * administrator ;-) 38 | * 39 | * @param RPCErrorCode 40 | */ 41 | @property (nonatomic, readonly) RPCErrorCode code; 42 | 43 | /** 44 | * RPC Error message 45 | * 46 | * A more detailed message describing the error. 47 | * 48 | * @param NSString 49 | */ 50 | @property (nonatomic, readonly, retain) NSString *message; 51 | 52 | /** 53 | * Some random data 54 | * 55 | * If the server supports sending debug data when server errors accours, it will be stored here 56 | * 57 | * @param id 58 | */ 59 | @property (nonatomic, readonly, retain) id data; 60 | 61 | #pragma mark - Methods 62 | 63 | // These methods is self explaining.. right? 64 | - (id) initWithCode:(RPCErrorCode) code; 65 | - (id) initWithCode:(RPCErrorCode) code message:(NSString*) message data:(id)data; 66 | + (id) errorWithCode:(RPCErrorCode) code; 67 | + (id) errorWithDictionary:(NSDictionary*) error; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/RPCRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCRequest.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class RPCResponse; 12 | 13 | // Callback type 14 | typedef void (^RPCRequestCallback)(RPCResponse *response); 15 | 16 | /** 17 | * RPC Request object. 18 | * 19 | * Always used to invoke a request to an endpoint. 20 | */ 21 | @interface RPCRequest : NSObject 22 | 23 | #pragma mark - Properties - 24 | 25 | /** 26 | * The used RPC Version. 27 | * This client only supports version 2.0 at the moment. 28 | * 29 | * @param NSString 30 | */ 31 | @property (nonatomic, retain) NSString *version; 32 | 33 | /** 34 | * The id that was used in the request. If id is nil the request is treated like an notification. 35 | * 36 | * @param NSString 37 | */ 38 | @property (nonatomic, retain) NSString *id; 39 | 40 | /** 41 | * Method to call at the RPC Server. 42 | * 43 | * @param NSString 44 | */ 45 | @property (nonatomic, retain) NSString *method; 46 | 47 | /** 48 | * Request params. Either named, un-named or nil 49 | * 50 | * @param id 51 | */ 52 | @property (nonatomic, retain) id params; 53 | 54 | /** 55 | * Callback to call whenever request is fininshed 56 | * 57 | * @param RPCRequestCallback 58 | */ 59 | @property (nonatomic, copy) RPCRequestCallback callback; 60 | 61 | #pragma mark - methods 62 | 63 | /** 64 | * Serialized requests object for json encodig 65 | * 66 | */ 67 | - (NSMutableDictionary*) serialize; 68 | 69 | /** 70 | * Helper method to get an autoreleased request object 71 | * 72 | * @param NSString method The method that this request if for 73 | * @return RPCRequest (autoreleased) 74 | */ 75 | + (id) requestWithMethod:(NSString*) method; 76 | 77 | /** 78 | * Helper method to get an autoreleased request object 79 | * 80 | * @param NSString method The method that this request if for 81 | * @param id params Some parameters to send along with the request, either named, un-named or nil 82 | * @return RPCRequest (autoreleased) 83 | */ 84 | + (id) requestWithMethod:(NSString*) method params:(id) params; 85 | 86 | /** 87 | * Helper method to get an autoreleased request object 88 | * 89 | * @param NSString method The method that this request if for 90 | * @param id params Some parameters to send along with the request, either named, un-named or nil 91 | * @param RPCRequestCallback the callback to call once the request is finished 92 | * @return RPCRequest (autoreleased) 93 | */ 94 | + (id) requestWithMethod:(NSString*) method params:(id) params callback:(RPCRequestCallback)callback; 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/RPCResponse.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCResponse.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RPCError.h" 11 | 12 | /** 13 | * RPC Resposne object 14 | * 15 | * This object is created when the server responds. 16 | */ 17 | @interface RPCResponse : NSObject 18 | 19 | /** 20 | * The used RPC Version. 21 | * 22 | * @param NSString 23 | */ 24 | @property (nonatomic, retain) NSString *version; 25 | 26 | /** 27 | * The id that was used in the request. 28 | * 29 | * @param NSString 30 | */ 31 | @property (nonatomic, retain) NSString *id; 32 | 33 | /** 34 | * RPC Error. If != nil it means there was an error 35 | * 36 | * @return RPCError 37 | */ 38 | @property (nonatomic, retain) RPCError *error; 39 | 40 | /** 41 | * An object represneting the result from the method on the server 42 | * 43 | * @param id 44 | */ 45 | @property (nonatomic, retain) id result; 46 | 47 | 48 | #pragma mark - Methods 49 | 50 | /** 51 | * Helper method to get an autoreleased RPCResponse object with an error set 52 | * 53 | * @param RPCError error The error for the response 54 | * @return RPCRequest 55 | */ 56 | + (id) responseWithError:(RPCError*)error; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/Headers/jsonrpc.h: -------------------------------------------------------------------------------- 1 | // 2 | // jsonrpc.h 3 | // jsonrpc 4 | // 5 | // Created by Rasmus Styrk on 02/10/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "JSONKit.h" 12 | 13 | #import "RPCError.h" 14 | #import "RPCRequest.h" 15 | #import "RPCResponse.h" 16 | 17 | #import "JSONRPCClient+Invoke.h" 18 | #import "JSONRPCClient+Notification.h" 19 | #import "JSONRPCClient+Multicall.h" 20 | 21 | #import "JSONRPCClient.h" 22 | 23 | @interface jsonrpc : NSObject 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/A/jsonrpc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styrken/objc-JSONRpc/13cafa39190e37d3df3ef86f411d6cc7e41c16d9/jsonrpc.framework/Versions/A/jsonrpc -------------------------------------------------------------------------------- /jsonrpc.framework/Versions/Current: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /jsonrpc.framework/jsonrpc: -------------------------------------------------------------------------------- 1 | Versions/Current/jsonrpc -------------------------------------------------------------------------------- /jsonrpc/jsonrpc-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'jsonrpc' target in the 'jsonrpc' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /jsonrpc/jsonrpc.h: -------------------------------------------------------------------------------- 1 | // 2 | // jsonrpc.h 3 | // jsonrpc 4 | // 5 | // Created by Rasmus Styrk on 02/10/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "JSONKit.h" 12 | 13 | #import "RPCError.h" 14 | #import "RPCRequest.h" 15 | #import "RPCResponse.h" 16 | 17 | #import "JSONRPCClient+Invoke.h" 18 | #import "JSONRPCClient+Notification.h" 19 | #import "JSONRPCClient+Multicall.h" 20 | 21 | #import "JSONRPCClient.h" 22 | 23 | @interface jsonrpc : NSObject 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /jsonrpc/jsonrpc.m: -------------------------------------------------------------------------------- 1 | // 2 | // jsonrpc.m 3 | // jsonrpc 4 | // 5 | // Created by Rasmus Styrk on 02/10/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "jsonrpc.h" 10 | 11 | @implementation jsonrpc 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /objc-JSONRpc.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXAggregateTarget section */ 10 | 3BF5DC1D161B10D000428FA7 /* framework */ = { 11 | isa = PBXAggregateTarget; 12 | buildConfigurationList = 3BF5DC1E161B10D000428FA7 /* Build configuration list for PBXAggregateTarget "framework" */; 13 | buildPhases = ( 14 | 3BF5DC23161B10F000428FA7 /* build_framework */, 15 | ); 16 | dependencies = ( 17 | 3BF5DC22161B10DA00428FA7 /* PBXTargetDependency */, 18 | ); 19 | name = framework; 20 | productName = framework; 21 | }; 22 | /* End PBXAggregateTarget section */ 23 | 24 | /* Begin PBXBuildFile section */ 25 | 3A210B7E1606786D003DBBF1 /* JSONRPCClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B771606786D003DBBF1 /* JSONRPCClient.m */; }; 26 | 3A210B7F1606786D003DBBF1 /* JSONRPCClient+Invoke.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B791606786D003DBBF1 /* JSONRPCClient+Invoke.m */; }; 27 | 3A210B801606786D003DBBF1 /* JSONRPCClient+Multicall.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B7B1606786D003DBBF1 /* JSONRPCClient+Multicall.m */; }; 28 | 3A210B811606786D003DBBF1 /* JSONRPCClient+Notification.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B7D1606786D003DBBF1 /* JSONRPCClient+Notification.m */; }; 29 | 3A9B622415ED2CD2009A74FB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A9B622315ED2CD2009A74FB /* UIKit.framework */; }; 30 | 3A9B622615ED2CD2009A74FB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A9B622515ED2CD2009A74FB /* Foundation.framework */; }; 31 | 3A9B622815ED2CD2009A74FB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A9B622715ED2CD2009A74FB /* CoreGraphics.framework */; }; 32 | 3A9B622E15ED2CD2009A74FB /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3A9B622C15ED2CD2009A74FB /* InfoPlist.strings */; }; 33 | 3A9B623015ED2CD2009A74FB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B622F15ED2CD2009A74FB /* main.m */; }; 34 | 3A9B623415ED2CD2009A74FB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B623315ED2CD2009A74FB /* AppDelegate.m */; }; 35 | 3A9B624615ED3010009A74FB /* RPCRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B624515ED3010009A74FB /* RPCRequest.m */; }; 36 | 3A9B624915ED3021009A74FB /* RPCError.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B624815ED3021009A74FB /* RPCError.m */; }; 37 | 3A9B624C15ED3030009A74FB /* RPCResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B624B15ED3030009A74FB /* RPCResponse.m */; }; 38 | 3A9B625E15ED4F8B009A74FB /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 3A9B625A15ED4F8B009A74FB /* CHANGELOG.md */; }; 39 | 3A9B625F15ED4F8B009A74FB /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B625C15ED4F8B009A74FB /* JSONKit.m */; }; 40 | 3A9B626015ED4F8B009A74FB /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 3A9B625D15ED4F8B009A74FB /* README.md */; }; 41 | 3B318280161D85220054C52B /* JSONKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A9B625B15ED4F8B009A74FB /* JSONKit.h */; }; 42 | 3BE89848161ACF0600AEB2CD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A9B622515ED2CD2009A74FB /* Foundation.framework */; }; 43 | 3BE8984D161ACF0600AEB2CD /* jsonrpc.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3BE8984C161ACF0600AEB2CD /* jsonrpc.h */; }; 44 | 3BE8984F161ACF0600AEB2CD /* jsonrpc.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BE8984E161ACF0600AEB2CD /* jsonrpc.m */; }; 45 | 3BE89854161ACF3A00AEB2CD /* RPCRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B624515ED3010009A74FB /* RPCRequest.m */; }; 46 | 3BE89855161ACF3B00AEB2CD /* RPCResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B624B15ED3030009A74FB /* RPCResponse.m */; }; 47 | 3BE89856161ACF3D00AEB2CD /* RPCError.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B624815ED3021009A74FB /* RPCError.m */; }; 48 | 3BE89857161ACF4000AEB2CD /* JSONRPCClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B771606786D003DBBF1 /* JSONRPCClient.m */; }; 49 | 3BE89858161ACF4200AEB2CD /* JSONRPCClient+Invoke.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B791606786D003DBBF1 /* JSONRPCClient+Invoke.m */; }; 50 | 3BE89859161ACF4400AEB2CD /* JSONRPCClient+Multicall.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B7B1606786D003DBBF1 /* JSONRPCClient+Multicall.m */; }; 51 | 3BE8985A161ACF4600AEB2CD /* JSONRPCClient+Notification.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A210B7D1606786D003DBBF1 /* JSONRPCClient+Notification.m */; }; 52 | 3BE8985B161ACF4C00AEB2CD /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9B625C15ED4F8B009A74FB /* JSONKit.m */; }; 53 | 3BE8985C161ACF5200AEB2CD /* RPCRequest.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A9B624415ED3010009A74FB /* RPCRequest.h */; }; 54 | 3BE8985D161ACF5300AEB2CD /* RPCResponse.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A9B624A15ED3030009A74FB /* RPCResponse.h */; }; 55 | 3BE8985F161ACF5C00AEB2CD /* RPCError.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A9B624715ED3021009A74FB /* RPCError.h */; }; 56 | 3BE89860161ACF5E00AEB2CD /* JSONRPCClient.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A210B761606786D003DBBF1 /* JSONRPCClient.h */; }; 57 | 3BE89861161ACF6200AEB2CD /* JSONRPCClient+Invoke.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A210B781606786D003DBBF1 /* JSONRPCClient+Invoke.h */; }; 58 | 3BE89862161ACF6400AEB2CD /* JSONRPCClient+Multicall.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A210B7A1606786D003DBBF1 /* JSONRPCClient+Multicall.h */; }; 59 | 3BE89863161ACF6700AEB2CD /* JSONRPCClient+Notification.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A210B7C1606786D003DBBF1 /* JSONRPCClient+Notification.h */; }; 60 | /* End PBXBuildFile section */ 61 | 62 | /* Begin PBXContainerItemProxy section */ 63 | 3BF5DC21161B10DA00428FA7 /* PBXContainerItemProxy */ = { 64 | isa = PBXContainerItemProxy; 65 | containerPortal = 3A9B621615ED2CD2009A74FB /* Project object */; 66 | proxyType = 1; 67 | remoteGlobalIDString = 3BE89846161ACF0600AEB2CD; 68 | remoteInfo = jsonrpc; 69 | }; 70 | /* End PBXContainerItemProxy section */ 71 | 72 | /* Begin PBXCopyFilesBuildPhase section */ 73 | 3BE89845161ACF0600AEB2CD /* CopyFiles */ = { 74 | isa = PBXCopyFilesBuildPhase; 75 | buildActionMask = 2147483647; 76 | dstPath = "include/${PRODUCT_NAME}"; 77 | dstSubfolderSpec = 16; 78 | files = ( 79 | 3B318280161D85220054C52B /* JSONKit.h in CopyFiles */, 80 | 3BE8984D161ACF0600AEB2CD /* jsonrpc.h in CopyFiles */, 81 | 3BE8985C161ACF5200AEB2CD /* RPCRequest.h in CopyFiles */, 82 | 3BE8985D161ACF5300AEB2CD /* RPCResponse.h in CopyFiles */, 83 | 3BE8985F161ACF5C00AEB2CD /* RPCError.h in CopyFiles */, 84 | 3BE89860161ACF5E00AEB2CD /* JSONRPCClient.h in CopyFiles */, 85 | 3BE89861161ACF6200AEB2CD /* JSONRPCClient+Invoke.h in CopyFiles */, 86 | 3BE89862161ACF6400AEB2CD /* JSONRPCClient+Multicall.h in CopyFiles */, 87 | 3BE89863161ACF6700AEB2CD /* JSONRPCClient+Notification.h in CopyFiles */, 88 | ); 89 | runOnlyForDeploymentPostprocessing = 0; 90 | }; 91 | /* End PBXCopyFilesBuildPhase section */ 92 | 93 | /* Begin PBXFileReference section */ 94 | 3A210B761606786D003DBBF1 /* JSONRPCClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSONRPCClient.h; path = "RPC Client/Client/JSONRPCClient.h"; sourceTree = ""; }; 95 | 3A210B771606786D003DBBF1 /* JSONRPCClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSONRPCClient.m; path = "RPC Client/Client/JSONRPCClient.m"; sourceTree = ""; }; 96 | 3A210B781606786D003DBBF1 /* JSONRPCClient+Invoke.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JSONRPCClient+Invoke.h"; path = "RPC Client/Client/JSONRPCClient+Invoke.h"; sourceTree = ""; }; 97 | 3A210B791606786D003DBBF1 /* JSONRPCClient+Invoke.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "JSONRPCClient+Invoke.m"; path = "RPC Client/Client/JSONRPCClient+Invoke.m"; sourceTree = ""; }; 98 | 3A210B7A1606786D003DBBF1 /* JSONRPCClient+Multicall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JSONRPCClient+Multicall.h"; path = "RPC Client/Client/JSONRPCClient+Multicall.h"; sourceTree = ""; }; 99 | 3A210B7B1606786D003DBBF1 /* JSONRPCClient+Multicall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "JSONRPCClient+Multicall.m"; path = "RPC Client/Client/JSONRPCClient+Multicall.m"; sourceTree = ""; }; 100 | 3A210B7C1606786D003DBBF1 /* JSONRPCClient+Notification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JSONRPCClient+Notification.h"; path = "RPC Client/Client/JSONRPCClient+Notification.h"; sourceTree = ""; }; 101 | 3A210B7D1606786D003DBBF1 /* JSONRPCClient+Notification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "JSONRPCClient+Notification.m"; path = "RPC Client/Client/JSONRPCClient+Notification.m"; sourceTree = ""; }; 102 | 3A9B621F15ED2CD2009A74FB /* objc-JSONRpc.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "objc-JSONRpc.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 103 | 3A9B622315ED2CD2009A74FB /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 104 | 3A9B622515ED2CD2009A74FB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 105 | 3A9B622715ED2CD2009A74FB /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 106 | 3A9B622B15ED2CD2009A74FB /* objc-JSONRpc-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "objc-JSONRpc-Info.plist"; sourceTree = ""; }; 107 | 3A9B622D15ED2CD2009A74FB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 108 | 3A9B622F15ED2CD2009A74FB /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 109 | 3A9B623115ED2CD2009A74FB /* objc-JSONRpc-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "objc-JSONRpc-Prefix.pch"; sourceTree = ""; }; 110 | 3A9B623215ED2CD2009A74FB /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 111 | 3A9B623315ED2CD2009A74FB /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 112 | 3A9B624415ED3010009A74FB /* RPCRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RPCRequest.h; path = "RPC Client/Models/RPCRequest.h"; sourceTree = ""; }; 113 | 3A9B624515ED3010009A74FB /* RPCRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RPCRequest.m; path = "RPC Client/Models/RPCRequest.m"; sourceTree = ""; }; 114 | 3A9B624715ED3021009A74FB /* RPCError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RPCError.h; path = "RPC Client/Models/RPCError.h"; sourceTree = ""; }; 115 | 3A9B624815ED3021009A74FB /* RPCError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RPCError.m; path = "RPC Client/Models/RPCError.m"; sourceTree = ""; }; 116 | 3A9B624A15ED3030009A74FB /* RPCResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RPCResponse.h; path = "RPC Client/Models/RPCResponse.h"; sourceTree = ""; }; 117 | 3A9B624B15ED3030009A74FB /* RPCResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RPCResponse.m; path = "RPC Client/Models/RPCResponse.m"; sourceTree = ""; }; 118 | 3A9B625A15ED4F8B009A74FB /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; 119 | 3A9B625B15ED4F8B009A74FB /* JSONKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONKit.h; sourceTree = ""; }; 120 | 3A9B625C15ED4F8B009A74FB /* JSONKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSONKit.m; sourceTree = ""; }; 121 | 3A9B625D15ED4F8B009A74FB /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = ""; }; 122 | 3BE89847161ACF0600AEB2CD /* libjsonrpc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libjsonrpc.a; sourceTree = BUILT_PRODUCTS_DIR; }; 123 | 3BE8984B161ACF0600AEB2CD /* jsonrpc-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "jsonrpc-Prefix.pch"; sourceTree = ""; }; 124 | 3BE8984C161ACF0600AEB2CD /* jsonrpc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = jsonrpc.h; sourceTree = ""; }; 125 | 3BE8984E161ACF0600AEB2CD /* jsonrpc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = jsonrpc.m; sourceTree = ""; }; 126 | /* End PBXFileReference section */ 127 | 128 | /* Begin PBXFrameworksBuildPhase section */ 129 | 3A9B621C15ED2CD2009A74FB /* Frameworks */ = { 130 | isa = PBXFrameworksBuildPhase; 131 | buildActionMask = 2147483647; 132 | files = ( 133 | 3A9B622415ED2CD2009A74FB /* UIKit.framework in Frameworks */, 134 | 3A9B622615ED2CD2009A74FB /* Foundation.framework in Frameworks */, 135 | 3A9B622815ED2CD2009A74FB /* CoreGraphics.framework in Frameworks */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | 3BE89844161ACF0600AEB2CD /* Frameworks */ = { 140 | isa = PBXFrameworksBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | 3BE89848161ACF0600AEB2CD /* Foundation.framework in Frameworks */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXFrameworksBuildPhase section */ 148 | 149 | /* Begin PBXGroup section */ 150 | 3A9B621415ED2CD2009A74FB = { 151 | isa = PBXGroup; 152 | children = ( 153 | 3A9B622915ED2CD2009A74FB /* objc-JSONRpc */, 154 | 3BE89849161ACF0600AEB2CD /* jsonrpc */, 155 | 3A9B622215ED2CD2009A74FB /* Frameworks */, 156 | 3A9B622015ED2CD2009A74FB /* Products */, 157 | ); 158 | sourceTree = ""; 159 | }; 160 | 3A9B622015ED2CD2009A74FB /* Products */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | 3A9B621F15ED2CD2009A74FB /* objc-JSONRpc.app */, 164 | 3BE89847161ACF0600AEB2CD /* libjsonrpc.a */, 165 | ); 166 | name = Products; 167 | sourceTree = ""; 168 | }; 169 | 3A9B622215ED2CD2009A74FB /* Frameworks */ = { 170 | isa = PBXGroup; 171 | children = ( 172 | 3A9B622315ED2CD2009A74FB /* UIKit.framework */, 173 | 3A9B622515ED2CD2009A74FB /* Foundation.framework */, 174 | 3A9B622715ED2CD2009A74FB /* CoreGraphics.framework */, 175 | ); 176 | name = Frameworks; 177 | sourceTree = ""; 178 | }; 179 | 3A9B622915ED2CD2009A74FB /* objc-JSONRpc */ = { 180 | isa = PBXGroup; 181 | children = ( 182 | 3A9B622A15ED2CD2009A74FB /* Supporting Files */, 183 | 3A9B623B15ED2CEC009A74FB /* RPC Client */, 184 | 3A9B623215ED2CD2009A74FB /* AppDelegate.h */, 185 | 3A9B623315ED2CD2009A74FB /* AppDelegate.m */, 186 | ); 187 | path = "objc-JSONRpc"; 188 | sourceTree = ""; 189 | }; 190 | 3A9B622A15ED2CD2009A74FB /* Supporting Files */ = { 191 | isa = PBXGroup; 192 | children = ( 193 | 3A9B622B15ED2CD2009A74FB /* objc-JSONRpc-Info.plist */, 194 | 3A9B622C15ED2CD2009A74FB /* InfoPlist.strings */, 195 | 3A9B622F15ED2CD2009A74FB /* main.m */, 196 | 3A9B623115ED2CD2009A74FB /* objc-JSONRpc-Prefix.pch */, 197 | ); 198 | name = "Supporting Files"; 199 | sourceTree = ""; 200 | }; 201 | 3A9B623B15ED2CEC009A74FB /* RPC Client */ = { 202 | isa = PBXGroup; 203 | children = ( 204 | 3A9B625815ED4F8B009A74FB /* Helpers */, 205 | 3A9B623D15ED2F5E009A74FB /* Models */, 206 | 3A9B623C15ED2F48009A74FB /* Client */, 207 | ); 208 | name = "RPC Client"; 209 | sourceTree = ""; 210 | }; 211 | 3A9B623C15ED2F48009A74FB /* Client */ = { 212 | isa = PBXGroup; 213 | children = ( 214 | 3A210B761606786D003DBBF1 /* JSONRPCClient.h */, 215 | 3A210B771606786D003DBBF1 /* JSONRPCClient.m */, 216 | 3A210B781606786D003DBBF1 /* JSONRPCClient+Invoke.h */, 217 | 3A210B791606786D003DBBF1 /* JSONRPCClient+Invoke.m */, 218 | 3A210B7A1606786D003DBBF1 /* JSONRPCClient+Multicall.h */, 219 | 3A210B7B1606786D003DBBF1 /* JSONRPCClient+Multicall.m */, 220 | 3A210B7C1606786D003DBBF1 /* JSONRPCClient+Notification.h */, 221 | 3A210B7D1606786D003DBBF1 /* JSONRPCClient+Notification.m */, 222 | ); 223 | name = Client; 224 | sourceTree = ""; 225 | }; 226 | 3A9B623D15ED2F5E009A74FB /* Models */ = { 227 | isa = PBXGroup; 228 | children = ( 229 | 3A9B624415ED3010009A74FB /* RPCRequest.h */, 230 | 3A9B624515ED3010009A74FB /* RPCRequest.m */, 231 | 3A9B624A15ED3030009A74FB /* RPCResponse.h */, 232 | 3A9B624B15ED3030009A74FB /* RPCResponse.m */, 233 | 3A9B624715ED3021009A74FB /* RPCError.h */, 234 | 3A9B624815ED3021009A74FB /* RPCError.m */, 235 | ); 236 | name = Models; 237 | sourceTree = ""; 238 | }; 239 | 3A9B625815ED4F8B009A74FB /* Helpers */ = { 240 | isa = PBXGroup; 241 | children = ( 242 | 3A9B625915ED4F8B009A74FB /* JSONKit */, 243 | ); 244 | name = Helpers; 245 | path = "RPC Client/Helpers"; 246 | sourceTree = ""; 247 | }; 248 | 3A9B625915ED4F8B009A74FB /* JSONKit */ = { 249 | isa = PBXGroup; 250 | children = ( 251 | 3A9B625A15ED4F8B009A74FB /* CHANGELOG.md */, 252 | 3A9B625D15ED4F8B009A74FB /* README.md */, 253 | 3A9B625B15ED4F8B009A74FB /* JSONKit.h */, 254 | 3A9B625C15ED4F8B009A74FB /* JSONKit.m */, 255 | ); 256 | path = JSONKit; 257 | sourceTree = ""; 258 | }; 259 | 3BE89849161ACF0600AEB2CD /* jsonrpc */ = { 260 | isa = PBXGroup; 261 | children = ( 262 | 3BE8984C161ACF0600AEB2CD /* jsonrpc.h */, 263 | 3BE8984E161ACF0600AEB2CD /* jsonrpc.m */, 264 | 3BE8984A161ACF0600AEB2CD /* Supporting Files */, 265 | ); 266 | path = jsonrpc; 267 | sourceTree = ""; 268 | }; 269 | 3BE8984A161ACF0600AEB2CD /* Supporting Files */ = { 270 | isa = PBXGroup; 271 | children = ( 272 | 3BE8984B161ACF0600AEB2CD /* jsonrpc-Prefix.pch */, 273 | ); 274 | name = "Supporting Files"; 275 | sourceTree = ""; 276 | }; 277 | /* End PBXGroup section */ 278 | 279 | /* Begin PBXNativeTarget section */ 280 | 3A9B621E15ED2CD2009A74FB /* objc-JSONRpc */ = { 281 | isa = PBXNativeTarget; 282 | buildConfigurationList = 3A9B623715ED2CD2009A74FB /* Build configuration list for PBXNativeTarget "objc-JSONRpc" */; 283 | buildPhases = ( 284 | 3A9B621B15ED2CD2009A74FB /* Sources */, 285 | 3A9B621C15ED2CD2009A74FB /* Frameworks */, 286 | 3A9B621D15ED2CD2009A74FB /* Resources */, 287 | ); 288 | buildRules = ( 289 | ); 290 | dependencies = ( 291 | ); 292 | name = "objc-JSONRpc"; 293 | productName = "objc-JSONRpc"; 294 | productReference = 3A9B621F15ED2CD2009A74FB /* objc-JSONRpc.app */; 295 | productType = "com.apple.product-type.application"; 296 | }; 297 | 3BE89846161ACF0600AEB2CD /* jsonrpc */ = { 298 | isa = PBXNativeTarget; 299 | buildConfigurationList = 3BE89852161ACF0600AEB2CD /* Build configuration list for PBXNativeTarget "jsonrpc" */; 300 | buildPhases = ( 301 | 3BE89843161ACF0600AEB2CD /* Sources */, 302 | 3BE89844161ACF0600AEB2CD /* Frameworks */, 303 | 3BE89845161ACF0600AEB2CD /* CopyFiles */, 304 | 3BF5DBFB161B0C8B00428FA7 /* prepare framework */, 305 | ); 306 | buildRules = ( 307 | ); 308 | dependencies = ( 309 | ); 310 | name = jsonrpc; 311 | productName = jsonrpc; 312 | productReference = 3BE89847161ACF0600AEB2CD /* libjsonrpc.a */; 313 | productType = "com.apple.product-type.library.static"; 314 | }; 315 | /* End PBXNativeTarget section */ 316 | 317 | /* Begin PBXProject section */ 318 | 3A9B621615ED2CD2009A74FB /* Project object */ = { 319 | isa = PBXProject; 320 | attributes = { 321 | LastUpgradeCheck = 0440; 322 | ORGANIZATIONNAME = "Rasmus Styrk"; 323 | }; 324 | buildConfigurationList = 3A9B621915ED2CD2009A74FB /* Build configuration list for PBXProject "objc-JSONRpc" */; 325 | compatibilityVersion = "Xcode 3.2"; 326 | developmentRegion = English; 327 | hasScannedForEncodings = 0; 328 | knownRegions = ( 329 | en, 330 | ); 331 | mainGroup = 3A9B621415ED2CD2009A74FB; 332 | productRefGroup = 3A9B622015ED2CD2009A74FB /* Products */; 333 | projectDirPath = ""; 334 | projectRoot = ""; 335 | targets = ( 336 | 3A9B621E15ED2CD2009A74FB /* objc-JSONRpc */, 337 | 3BE89846161ACF0600AEB2CD /* jsonrpc */, 338 | 3BF5DC1D161B10D000428FA7 /* framework */, 339 | ); 340 | }; 341 | /* End PBXProject section */ 342 | 343 | /* Begin PBXResourcesBuildPhase section */ 344 | 3A9B621D15ED2CD2009A74FB /* Resources */ = { 345 | isa = PBXResourcesBuildPhase; 346 | buildActionMask = 2147483647; 347 | files = ( 348 | 3A9B622E15ED2CD2009A74FB /* InfoPlist.strings in Resources */, 349 | 3A9B625E15ED4F8B009A74FB /* CHANGELOG.md in Resources */, 350 | 3A9B626015ED4F8B009A74FB /* README.md in Resources */, 351 | ); 352 | runOnlyForDeploymentPostprocessing = 0; 353 | }; 354 | /* End PBXResourcesBuildPhase section */ 355 | 356 | /* Begin PBXShellScriptBuildPhase section */ 357 | 3BF5DBFB161B0C8B00428FA7 /* prepare framework */ = { 358 | isa = PBXShellScriptBuildPhase; 359 | buildActionMask = 2147483647; 360 | files = ( 361 | ); 362 | inputPaths = ( 363 | ); 364 | name = "prepare framework"; 365 | outputPaths = ( 366 | ); 367 | runOnlyForDeploymentPostprocessing = 0; 368 | shellPath = /bin/sh; 369 | shellScript = "set -e\n\nmkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Versions/A/Headers\"\n\n# Link the \"Current\" version to \"A\"\n/bin/ln -sfh A \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Versions/Current\"\n/bin/ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Headers\"\n/bin/ln -sfh \"Versions/Current/${PRODUCT_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}\"\n\n# The -a ensures that the headers maintain the source modification date so that we don't constantly\n# cause propagating rebuilds of files that import these headers.\n/bin/cp -a \"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework/Versions/A/Headers\""; 370 | }; 371 | 3BF5DC23161B10F000428FA7 /* build_framework */ = { 372 | isa = PBXShellScriptBuildPhase; 373 | buildActionMask = 2147483647; 374 | files = ( 375 | ); 376 | inputPaths = ( 377 | ); 378 | name = build_framework; 379 | outputPaths = ( 380 | ); 381 | runOnlyForDeploymentPostprocessing = 0; 382 | shellPath = /bin/sh; 383 | shellScript = "set -e\nset +u\n# Avoid recursively calling this script.\nif [[ $SF_MASTER_SCRIPT_RUNNING ]]\nthen\nexit 0\nfi\nset -u\nexport SF_MASTER_SCRIPT_RUNNING=1\n\nSF_TARGET_NAME=\"jsonrpc\"\nSF_EXECUTABLE_PATH=\"lib${SF_TARGET_NAME}.a\"\nSF_WRAPPER_NAME=\"${SF_TARGET_NAME}.framework\"\n\n# The following conditionals come from\n# https://github.com/kstenerud/iOS-Universal-Framework\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\nSF_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\necho \"Could not find platform name from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\nSF_SDK_VERSION=${BASH_REMATCH[1]}\nelse\necho \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SF_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\nSF_OTHER_PLATFORM=iphonesimulator\nelse\nSF_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$SF_SDK_PLATFORM$ ]]\nthen\nSF_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${SF_OTHER_PLATFORM}\"\nelse\necho \"Could not find platform name from build products directory: $BUILT_PRODUCTS_DIR\"\nexit 1\nfi\n\n# Build the other platform.\nxcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${SF_OTHER_PLATFORM}${SF_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" OBJROOT=\"${OBJROOT}\" BUILD_ROOT=\"${BUILD_ROOT}\" SYMROOT=\"${SYMROOT}\" $ACTION\n\n# Smash the two static libraries into one fat binary and store it in the .framework\nlipo -create \"${BUILT_PRODUCTS_DIR}/${SF_EXECUTABLE_PATH}\" \"${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_EXECUTABLE_PATH}\" -output \"${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/Versions/A/${SF_TARGET_NAME}\"\n\n# Copy the binary to the other architecture folder to have a complete framework in both.\ncp -a \"${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/Versions/A/${SF_TARGET_NAME}\" \"${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/Versions/A/${SF_TARGET_NAME}\"\n\nrm -rf \"${PROJECT_DIR}/${SF_WRAPPER_NAME}\"\ncp -a \"${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}\" \"${PROJECT_DIR}\"\n"; 384 | }; 385 | /* End PBXShellScriptBuildPhase section */ 386 | 387 | /* Begin PBXSourcesBuildPhase section */ 388 | 3A9B621B15ED2CD2009A74FB /* Sources */ = { 389 | isa = PBXSourcesBuildPhase; 390 | buildActionMask = 2147483647; 391 | files = ( 392 | 3A9B623015ED2CD2009A74FB /* main.m in Sources */, 393 | 3A9B623415ED2CD2009A74FB /* AppDelegate.m in Sources */, 394 | 3A9B624615ED3010009A74FB /* RPCRequest.m in Sources */, 395 | 3A9B624915ED3021009A74FB /* RPCError.m in Sources */, 396 | 3A9B624C15ED3030009A74FB /* RPCResponse.m in Sources */, 397 | 3A9B625F15ED4F8B009A74FB /* JSONKit.m in Sources */, 398 | 3A210B7E1606786D003DBBF1 /* JSONRPCClient.m in Sources */, 399 | 3A210B7F1606786D003DBBF1 /* JSONRPCClient+Invoke.m in Sources */, 400 | 3A210B801606786D003DBBF1 /* JSONRPCClient+Multicall.m in Sources */, 401 | 3A210B811606786D003DBBF1 /* JSONRPCClient+Notification.m in Sources */, 402 | ); 403 | runOnlyForDeploymentPostprocessing = 0; 404 | }; 405 | 3BE89843161ACF0600AEB2CD /* Sources */ = { 406 | isa = PBXSourcesBuildPhase; 407 | buildActionMask = 2147483647; 408 | files = ( 409 | 3BE8984F161ACF0600AEB2CD /* jsonrpc.m in Sources */, 410 | 3BE89854161ACF3A00AEB2CD /* RPCRequest.m in Sources */, 411 | 3BE89855161ACF3B00AEB2CD /* RPCResponse.m in Sources */, 412 | 3BE89856161ACF3D00AEB2CD /* RPCError.m in Sources */, 413 | 3BE89857161ACF4000AEB2CD /* JSONRPCClient.m in Sources */, 414 | 3BE89858161ACF4200AEB2CD /* JSONRPCClient+Invoke.m in Sources */, 415 | 3BE89859161ACF4400AEB2CD /* JSONRPCClient+Multicall.m in Sources */, 416 | 3BE8985A161ACF4600AEB2CD /* JSONRPCClient+Notification.m in Sources */, 417 | 3BE8985B161ACF4C00AEB2CD /* JSONKit.m in Sources */, 418 | ); 419 | runOnlyForDeploymentPostprocessing = 0; 420 | }; 421 | /* End PBXSourcesBuildPhase section */ 422 | 423 | /* Begin PBXTargetDependency section */ 424 | 3BF5DC22161B10DA00428FA7 /* PBXTargetDependency */ = { 425 | isa = PBXTargetDependency; 426 | target = 3BE89846161ACF0600AEB2CD /* jsonrpc */; 427 | targetProxy = 3BF5DC21161B10DA00428FA7 /* PBXContainerItemProxy */; 428 | }; 429 | /* End PBXTargetDependency section */ 430 | 431 | /* Begin PBXVariantGroup section */ 432 | 3A9B622C15ED2CD2009A74FB /* InfoPlist.strings */ = { 433 | isa = PBXVariantGroup; 434 | children = ( 435 | 3A9B622D15ED2CD2009A74FB /* en */, 436 | ); 437 | name = InfoPlist.strings; 438 | sourceTree = ""; 439 | }; 440 | /* End PBXVariantGroup section */ 441 | 442 | /* Begin XCBuildConfiguration section */ 443 | 3A9B623515ED2CD2009A74FB /* Debug */ = { 444 | isa = XCBuildConfiguration; 445 | buildSettings = { 446 | ALWAYS_SEARCH_USER_PATHS = NO; 447 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 448 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 449 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 450 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 451 | COPY_PHASE_STRIP = NO; 452 | GCC_C_LANGUAGE_STANDARD = gnu99; 453 | GCC_DYNAMIC_NO_PIC = NO; 454 | GCC_OPTIMIZATION_LEVEL = 0; 455 | GCC_PREPROCESSOR_DEFINITIONS = ( 456 | "DEBUG=1", 457 | "$(inherited)", 458 | ); 459 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 460 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 461 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 462 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 463 | GCC_WARN_UNUSED_VARIABLE = YES; 464 | IPHONEOS_DEPLOYMENT_TARGET = 5.1; 465 | SDKROOT = iphoneos; 466 | TARGETED_DEVICE_FAMILY = "1,2"; 467 | }; 468 | name = Debug; 469 | }; 470 | 3A9B623615ED2CD2009A74FB /* Release */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | ALWAYS_SEARCH_USER_PATHS = NO; 474 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 475 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 476 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 477 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 478 | COPY_PHASE_STRIP = YES; 479 | GCC_C_LANGUAGE_STANDARD = gnu99; 480 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 481 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 482 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 483 | GCC_WARN_UNUSED_VARIABLE = YES; 484 | IPHONEOS_DEPLOYMENT_TARGET = 5.1; 485 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 486 | SDKROOT = iphoneos; 487 | TARGETED_DEVICE_FAMILY = "1,2"; 488 | VALIDATE_PRODUCT = YES; 489 | }; 490 | name = Release; 491 | }; 492 | 3A9B623815ED2CD2009A74FB /* Debug */ = { 493 | isa = XCBuildConfiguration; 494 | buildSettings = { 495 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 496 | GCC_PREFIX_HEADER = "objc-JSONRpc/objc-JSONRpc-Prefix.pch"; 497 | INFOPLIST_FILE = "objc-JSONRpc/objc-JSONRpc-Info.plist"; 498 | PRODUCT_NAME = "$(TARGET_NAME)"; 499 | WRAPPER_EXTENSION = app; 500 | }; 501 | name = Debug; 502 | }; 503 | 3A9B623915ED2CD2009A74FB /* Release */ = { 504 | isa = XCBuildConfiguration; 505 | buildSettings = { 506 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 507 | GCC_PREFIX_HEADER = "objc-JSONRpc/objc-JSONRpc-Prefix.pch"; 508 | INFOPLIST_FILE = "objc-JSONRpc/objc-JSONRpc-Info.plist"; 509 | PRODUCT_NAME = "$(TARGET_NAME)"; 510 | WRAPPER_EXTENSION = app; 511 | }; 512 | name = Release; 513 | }; 514 | 3BE89850161ACF0600AEB2CD /* Debug */ = { 515 | isa = XCBuildConfiguration; 516 | buildSettings = { 517 | CLANG_CXX_LIBRARY = "libc++"; 518 | CLANG_WARN_EMPTY_BODY = YES; 519 | COPY_PHASE_STRIP = NO; 520 | DEAD_CODE_STRIPPING = NO; 521 | DSTROOT = /tmp/jsonrpc.dst; 522 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 523 | GCC_PREFIX_HEADER = "jsonrpc/jsonrpc-Prefix.pch"; 524 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 525 | OTHER_LDFLAGS = "-ObjC"; 526 | PRODUCT_NAME = "$(TARGET_NAME)"; 527 | PUBLIC_HEADERS_FOLDER_PATH = include/jsonrpc/; 528 | SKIP_INSTALL = YES; 529 | STRIP_STYLE = "non-global"; 530 | }; 531 | name = Debug; 532 | }; 533 | 3BE89851161ACF0600AEB2CD /* Release */ = { 534 | isa = XCBuildConfiguration; 535 | buildSettings = { 536 | CLANG_CXX_LIBRARY = "libc++"; 537 | CLANG_WARN_EMPTY_BODY = YES; 538 | COPY_PHASE_STRIP = NO; 539 | DEAD_CODE_STRIPPING = NO; 540 | DSTROOT = /tmp/jsonrpc.dst; 541 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 542 | GCC_PREFIX_HEADER = "jsonrpc/jsonrpc-Prefix.pch"; 543 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 544 | OTHER_LDFLAGS = "-ObjC"; 545 | PRODUCT_NAME = "$(TARGET_NAME)"; 546 | PUBLIC_HEADERS_FOLDER_PATH = include/jsonrpc/; 547 | SKIP_INSTALL = YES; 548 | STRIP_STYLE = "non-global"; 549 | }; 550 | name = Release; 551 | }; 552 | 3BF5DC1F161B10D000428FA7 /* Debug */ = { 553 | isa = XCBuildConfiguration; 554 | buildSettings = { 555 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 556 | OTHER_LDFLAGS = "-ObjC"; 557 | PRODUCT_NAME = "$(TARGET_NAME)"; 558 | SEPARATE_STRIP = NO; 559 | }; 560 | name = Debug; 561 | }; 562 | 3BF5DC20161B10D000428FA7 /* Release */ = { 563 | isa = XCBuildConfiguration; 564 | buildSettings = { 565 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 566 | OTHER_LDFLAGS = "-ObjC"; 567 | PRODUCT_NAME = "$(TARGET_NAME)"; 568 | SEPARATE_STRIP = NO; 569 | }; 570 | name = Release; 571 | }; 572 | /* End XCBuildConfiguration section */ 573 | 574 | /* Begin XCConfigurationList section */ 575 | 3A9B621915ED2CD2009A74FB /* Build configuration list for PBXProject "objc-JSONRpc" */ = { 576 | isa = XCConfigurationList; 577 | buildConfigurations = ( 578 | 3A9B623515ED2CD2009A74FB /* Debug */, 579 | 3A9B623615ED2CD2009A74FB /* Release */, 580 | ); 581 | defaultConfigurationIsVisible = 0; 582 | defaultConfigurationName = Release; 583 | }; 584 | 3A9B623715ED2CD2009A74FB /* Build configuration list for PBXNativeTarget "objc-JSONRpc" */ = { 585 | isa = XCConfigurationList; 586 | buildConfigurations = ( 587 | 3A9B623815ED2CD2009A74FB /* Debug */, 588 | 3A9B623915ED2CD2009A74FB /* Release */, 589 | ); 590 | defaultConfigurationIsVisible = 0; 591 | defaultConfigurationName = Release; 592 | }; 593 | 3BE89852161ACF0600AEB2CD /* Build configuration list for PBXNativeTarget "jsonrpc" */ = { 594 | isa = XCConfigurationList; 595 | buildConfigurations = ( 596 | 3BE89850161ACF0600AEB2CD /* Debug */, 597 | 3BE89851161ACF0600AEB2CD /* Release */, 598 | ); 599 | defaultConfigurationIsVisible = 0; 600 | defaultConfigurationName = Release; 601 | }; 602 | 3BF5DC1E161B10D000428FA7 /* Build configuration list for PBXAggregateTarget "framework" */ = { 603 | isa = XCConfigurationList; 604 | buildConfigurations = ( 605 | 3BF5DC1F161B10D000428FA7 /* Debug */, 606 | 3BF5DC20161B10D000428FA7 /* Release */, 607 | ); 608 | defaultConfigurationIsVisible = 0; 609 | defaultConfigurationName = Release; 610 | }; 611 | /* End XCConfigurationList section */ 612 | }; 613 | rootObject = 3A9B621615ED2CD2009A74FB /* Project object */; 614 | } 615 | -------------------------------------------------------------------------------- /objc-JSONRpc.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objc-JSONRpc.xcodeproj/project.xcworkspace/xcuserdata/rasmus.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styrken/objc-JSONRpc/13cafa39190e37d3df3ef86f411d6cc7e41c16d9/objc-JSONRpc.xcodeproj/project.xcworkspace/xcuserdata/rasmus.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /objc-JSONRpc.xcodeproj/xcuserdata/rasmus.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /objc-JSONRpc.xcodeproj/xcuserdata/rasmus.xcuserdatad/xcschemes/objc-JSONRpc.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /objc-JSONRpc.xcodeproj/xcuserdata/rasmus.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | objc-JSONRpc.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 3A9B621E15ED2CD2009A74FB 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /objc-JSONRpc/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /objc-JSONRpc/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "JSONRPCClient+Invoke.h" // To allow use of invokes 11 | #import "JSONRPCClient+Notification.h" // To allow use of notifications 12 | #import "JSONRPCClient+Multicall.h" // Add multicall support 13 | 14 | @implementation AppDelegate 15 | 16 | - (void)dealloc 17 | { 18 | [_window release]; 19 | [super dealloc]; 20 | } 21 | 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 23 | { 24 | // Standard stuff 25 | self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 26 | self.window.backgroundColor = [UIColor whiteColor]; 27 | [self.window makeKeyAndVisible]; 28 | 29 | // RPC Test 30 | JSONRPCClient *rpc = [[JSONRPCClient alloc] initWithServiceEndpoint:@"http://..."]; 31 | 32 | [rpc invoke:@"getAppleProductIdentifiers" params:nil onCompleted:^(RPCResponse *response) { 33 | 34 | NSLog(@"getAppleProductIdentifiers"); 35 | NSLog(@"Respone: %@", response); 36 | NSLog(@"Error: %@", response.error); 37 | NSLog(@"Result: %@", response.result); 38 | 39 | }]; 40 | 41 | [rpc invoke:@"validateAppleReceipt" params:nil onSuccess:^(RPCResponse *response) { 42 | 43 | NSLog(@"validateAppleReceipt"); 44 | NSLog(@"Respone: %@", response); 45 | NSLog(@"Result: %@", response.result); 46 | 47 | 48 | } onFailure:^(RPCError *error) { 49 | 50 | NSLog(@"validateAppleReceipt"); 51 | NSLog(@"Error: %@", error); 52 | 53 | }]; 54 | 55 | [rpc notify:@"helloWorld"]; 56 | 57 | [rpc batch:[RPCRequest requestWithMethod:@"helloWorld" params:nil callback:^(RPCResponse *response) { 58 | NSLog(@"Multicall Response is: %@", response); 59 | NSLog(@"Multicall Response error: %@", response.error); 60 | 61 | }], [RPCRequest requestWithMethod:@"helloWorld"], [RPCRequest requestWithMethod:@"helloWorld"], nil]; 62 | 63 | [rpc postRequest:[RPCRequest requestWithMethod:@"helloWorld" params:nil callback:^(RPCResponse *response) { 64 | NSLog(@"Sync request: %@", response); 65 | NSLog(@"Sync request error: %@", response.error); 66 | 67 | }] async:NO]; 68 | 69 | 70 | [rpc release]; 71 | 72 | 73 | 74 | 75 | self.window.rootViewController = [[[UIViewController alloc] init] autorelease]; 76 | 77 | return YES; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient+Invoke.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Invoke.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 9/16/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | 11 | // Few other callback types (default RPCCompletedCallback is defined inside BaseRPCClient.h) 12 | typedef void (^RPCSuccessCallback)(RPCResponse *response); 13 | typedef void (^RPCFailedCallback)(RPCError *error); 14 | 15 | /** 16 | * Invoking 17 | * 18 | * - Adds invoking of methods on the remote server through the jsonrpcclient class 19 | */ 20 | @interface JSONRPCClient (Invoke) 21 | 22 | /** 23 | * Invokes a RPCRequest against the end point. 24 | * 25 | * @param RPCRequest reqeust The request to invoke 26 | * @return NSString The used request id. Can be used to match callback's if neccesary 27 | */ 28 | - (NSString *) invoke:(RPCRequest*) request; 29 | 30 | /** 31 | * Invokes a method against the end point. This method actually generates an RPCRequest object and calls invoke:request 32 | * 33 | * @param NSString method The method to invoke 34 | * @param id Either named or un-named parameter list (or nil) 35 | * @param RPCCompletedCallback A callback method to invoke when request is done (or any error accours) 36 | * @return NSString The used request id. Can be used to match callback's if neccesary 37 | */ 38 | - (NSString *) invoke:(NSString*) method params:(id) params onCompleted:(RPCRequestCallback)callback; 39 | 40 | /** 41 | * Invokes a method against endpoint providing a way to define both a success callback and a failure callback. 42 | * 43 | * This method simply wraps invoke:method:params:onCompleted 44 | * 45 | * @param NSString method The method to invoke 46 | * @param id Either named or un-named parameter list (or nil) 47 | * @param RPCSuccessCallback A callback method to invoke when request finishes successfull 48 | * @param RPCFailedCallback A callback method to invoke when request finishes with an error 49 | * @return NSString The used request id. Can be used to match callback's if neccesary 50 | */ 51 | - (NSString *) invoke:(NSString*) method params:(id) params onSuccess:(RPCSuccessCallback)successCallback onFailure:(RPCFailedCallback)failedCallback; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient+Invoke.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Invoke.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 9/16/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient+Invoke.h" 10 | #import "JSONKit.h" 11 | 12 | @implementation JSONRPCClient (Invoke) 13 | 14 | - (NSString *) invoke:(RPCRequest*) request 15 | { 16 | [self postRequests:[NSArray arrayWithObject:request]]; 17 | 18 | return request.id; 19 | } 20 | 21 | - (NSString *) invoke:(NSString *)method params:(id)params onCompleted:(RPCRequestCallback)callback 22 | { 23 | RPCRequest *request = [[RPCRequest alloc] init]; 24 | request.method = method; 25 | request.params = params; 26 | request.callback = callback; 27 | 28 | return [self invoke:[request autorelease]]; 29 | } 30 | 31 | - (NSString *) invoke:(NSString*) method params:(id) params onSuccess:(RPCSuccessCallback)successCallback onFailure:(RPCFailedCallback)failedCallback 32 | { 33 | return [self invoke:method params:params onCompleted:^(RPCResponse *response) { 34 | 35 | if(response.error) 36 | failedCallback(response.error); 37 | else 38 | successCallback(response); 39 | }]; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient+Multicall.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Invoke.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/29/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | 11 | /** 12 | * Multicall 13 | * 14 | * - Adds invoking of multicalls to the remote server through the jsonrpcclient class 15 | */ 16 | @interface JSONRPCClient (Multicall) 17 | 18 | /** 19 | * Sends batch of RPCRequest objects to the server. The call to this method must be nil terminated. 20 | * 21 | * @param RPCRequest request The first request to send 22 | * @param ...A list of RPCRequest objects to send, must be nil terminated 23 | */ 24 | - (void) batch:(RPCRequest*) request, ...; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient+Multicall.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Invoke.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/29/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient+Multicall.h" 10 | #import "JSONRPCClient+Invoke.h" 11 | #import "JSONKit.h" 12 | 13 | @implementation JSONRPCClient (Multicall) 14 | 15 | - (void) batch:(RPCRequest*) request, ... 16 | { 17 | va_list argument_list; 18 | 19 | NSMutableArray *tmpRequests = [[NSMutableArray alloc] init]; 20 | 21 | if(request) 22 | [tmpRequests addObject:request]; 23 | 24 | va_start(argument_list, request); 25 | 26 | RPCRequest *r; 27 | while((r = va_arg(argument_list, RPCRequest*))) 28 | [tmpRequests addObject:r]; 29 | 30 | va_end(argument_list); 31 | 32 | if(tmpRequests.count > 0 ) 33 | [self postRequests:tmpRequests]; 34 | 35 | [tmpRequests release]; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient+Notification.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Notifications.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 03/09/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | 11 | /** 12 | * Notificiation 13 | * 14 | * - Implements a way to use notifications in json rpc client. 15 | * 16 | * Its important to understand that notifications does not * allow using callbacks and therefor you 17 | * need to make sure you call your server in the right way since there is no telling if * your notification was 18 | * successfull or not. 19 | */ 20 | @interface JSONRPCClient (Notification) 21 | 22 | /** 23 | * Sends a notification to json rpc server. 24 | * 25 | * @param NSString method Method to call 26 | */ 27 | - (void) notify:(NSString *)method; 28 | 29 | /** 30 | * Sends a notification to json rpc server. 31 | * 32 | * @param NSString method Method to call 33 | * @param id Either named or un-named parameter list (or nil) 34 | */ 35 | - (void) notify:(NSString *)method params:(id)params; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient+Notification.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCClient+Notifications.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 03/09/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient+Notification.h" 10 | #import "JSONRPCClient+Invoke.h" 11 | 12 | @implementation JSONRPCClient (Notification) 13 | 14 | - (void) notify:(NSString *)method params:(id)params 15 | { 16 | RPCRequest *request = [[RPCRequest alloc] init]; 17 | request.method = method; 18 | request.params = params; 19 | request.id = nil; // Id must be nil when sending notifications 20 | 21 | [self invoke:[request autorelease]]; 22 | } 23 | 24 | - (void) notify:(NSString *)method 25 | { 26 | [self notify:method params:nil]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCJSONClient.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | // Hack to allow categories to be used withing a static library/framework 10 | #define STATIC_CATEGORY(name) @interface STATIC_CATEGORY##name @end @implementation STATIC_CATEGORY##name @end 11 | 12 | #import 13 | #import "RPCRequest.h" 14 | #import "RPCError.h" 15 | #import "RPCResponse.h" 16 | 17 | /** 18 | * JSONRPCClient 19 | * 20 | * Provides means to communicate with the RPC server and is responsible of serializing/parsing requests 21 | * that is send and recieved. 22 | * 23 | * Handles calling of RPCRequest callbacks and generates RPCResponse/RPCError objects. 24 | * 25 | * Retains requests while they are completing and manages calling of callback's. 26 | */ 27 | @interface JSONRPCClient : NSObject 28 | 29 | #pragma mark - Properties - 30 | 31 | /** 32 | * What service endpoint we talk to. Just a simple string containing an URL. 33 | * It will later be converted to an NSURL Object, so anything that NSURL Supports 34 | * is valid- 35 | */ 36 | @property (nonatomic, retain) NSString *serviceEndpoint; 37 | 38 | /** 39 | * All the reqeusts that is being executed is added to this statck 40 | */ 41 | @property (nonatomic, retain) NSMutableDictionary *requests; 42 | 43 | /** 44 | * All returned data from the server is saved into this dictionary for later processing 45 | */ 46 | @property (nonatomic, retain) NSMutableDictionary *requestData; 47 | 48 | #pragma mark - Methods 49 | 50 | /** 51 | * Inits RPC Client with a specific end point. 52 | * 53 | * @param NSString endpoint Should be some kind of standard URL 54 | * @return RPCClient 55 | */ 56 | - (id) initWithServiceEndpoint:(NSString*) endpoint; 57 | 58 | /** 59 | * Post requests syncronous 60 | * 61 | * Posts requests to the server via HTTP post. Always uses multicall to simplify handling 62 | * of responses. 63 | * 64 | * If the server your talking with do not understand multicall then you have a problem. 65 | */ 66 | - (void) postRequests:(NSArray*)requests; 67 | 68 | /** 69 | * Post Requests Async 70 | * 71 | * Posts requests to the server via HTTP post. Always uses multicall to simplify handling 72 | * of responses. 73 | * 74 | * If the server your talking with do not understand multicall then you have a problem. 75 | * 76 | */ 77 | - (void) postRequests:(NSArray *)requests async:(BOOL)async; 78 | 79 | /** 80 | * Posts a single single request 81 | * 82 | */ 83 | - (void) postRequest:(RPCRequest*)request async:(BOOL)async; 84 | 85 | /** 86 | * Sends a synchronous request that returns the response object 87 | * instead of using callbacks 88 | */ 89 | - (RPCResponse*) sendSynchronousRequest:(RPCRequest*)request; 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Client/JSONRPCClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // RPCJSONClient.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "JSONRPCClient.h" 10 | #import "JSONKit.h" 11 | 12 | @implementation JSONRPCClient 13 | 14 | @synthesize serviceEndpoint = _serviceEndpoint; 15 | @synthesize requests = _requests; 16 | @synthesize requestData = _requestData; 17 | 18 | - (id) initWithServiceEndpoint:(NSString*) endpoint 19 | { 20 | self = [super init]; 21 | 22 | if(self) 23 | { 24 | self.serviceEndpoint = endpoint; 25 | self.requests = [[[NSMutableDictionary alloc] init] autorelease]; 26 | self.requestData = [[[NSMutableDictionary alloc] init] autorelease]; 27 | } 28 | 29 | return self; 30 | } 31 | 32 | - (void) dealloc 33 | { 34 | [_serviceEndpoint release]; 35 | [_requests release]; 36 | [_requestData release]; 37 | 38 | [super dealloc]; 39 | } 40 | 41 | #pragma mark - Helpers 42 | 43 | - (void) postRequest:(RPCRequest*)request async:(BOOL)async 44 | { 45 | [self postRequests:[NSArray arrayWithObject:request] async:async]; 46 | } 47 | 48 | - (void) postRequests:(NSArray*)requests 49 | { 50 | [self postRequests:requests async:YES]; 51 | } 52 | 53 | - (void) postRequests:(NSArray *)requests async:(BOOL)async 54 | { 55 | NSMutableArray *serializedRequests = [[NSMutableArray alloc] initWithCapacity:requests.count]; 56 | 57 | for(RPCRequest *request in requests) 58 | [serializedRequests addObject:[request serialize]]; 59 | 60 | NSError *jsonError; 61 | NSData *payload = [serializedRequests JSONDataWithOptions:JKSerializeOptionNone error:&jsonError]; 62 | [serializedRequests release]; 63 | 64 | if(jsonError != nil) 65 | [self handleFailedRequests:requests withRPCError:[RPCError errorWithCode:RPCParseError]]; 66 | else 67 | { 68 | NSMutableURLRequest *serviceRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.serviceEndpoint]]; 69 | [serviceRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 70 | [serviceRequest setValue:@"objc-JSONRpc/1.0" forHTTPHeaderField:@"User-Agent"]; 71 | 72 | [serviceRequest setValue:[NSString stringWithFormat:@"%i", payload.length] forHTTPHeaderField:@"Content-Length"]; 73 | [serviceRequest setHTTPMethod:@"POST"]; 74 | [serviceRequest setHTTPBody:payload]; 75 | 76 | if(async) 77 | { 78 | #ifndef __clang_analyzer__ 79 | NSURLConnection *serviceEndpointConnection = [[NSURLConnection alloc] initWithRequest:serviceRequest delegate:self]; 80 | #endif 81 | 82 | NSMutableData *rData = [[NSMutableData alloc] init]; 83 | [self.requestData setObject:rData forKey:[NSNumber numberWithInt:(int)serviceEndpointConnection]]; 84 | [self.requests setObject:requests forKey:[NSNumber numberWithInt:(int)serviceEndpointConnection]]; 85 | [rData release]; 86 | [serviceRequest release]; 87 | } 88 | else 89 | { 90 | NSURLResponse *response = nil; 91 | NSError *error = nil; 92 | NSData *data = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:&response error:&error]; 93 | 94 | if(data != nil) 95 | [self handleData:data withRequests:requests]; 96 | else 97 | [self handleFailedRequests:requests withRPCError:[RPCError errorWithCode:RPCNetworkError]]; 98 | } 99 | } 100 | } 101 | 102 | - (RPCResponse*) sendSynchronousRequest:(RPCRequest *)request 103 | { 104 | RPCResponse *response = [[RPCResponse alloc] init]; 105 | 106 | NSError *jsonError = nil; 107 | NSData *payload = [[request serialize] JSONDataWithOptions:JKSerializeOptionNone error:&jsonError]; 108 | 109 | if(jsonError == nil) 110 | { 111 | NSMutableURLRequest *serviceRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.serviceEndpoint]]; 112 | [serviceRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 113 | [serviceRequest setValue:@"objc-JSONRpc/1.0" forHTTPHeaderField:@"User-Agent"]; 114 | 115 | [serviceRequest setValue:[NSString stringWithFormat:@"%i", payload.length] forHTTPHeaderField:@"Content-Length"]; 116 | [serviceRequest setHTTPMethod:@"POST"]; 117 | [serviceRequest setHTTPBody:payload]; 118 | 119 | NSURLResponse *serviceResponse = nil; 120 | NSError *error = nil; 121 | NSData *data = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:&serviceResponse error:&error]; 122 | 123 | if(data != nil) 124 | { 125 | jsonError = nil; 126 | id result = [data objectFromJSONDataWithParseOptions:JKParseOptionNone error:&jsonError]; 127 | 128 | if(data.length == 0) 129 | response.error = [RPCError errorWithCode:RPCServerError]; 130 | else if(jsonError) 131 | response.error = [RPCError errorWithCode:RPCParseError]; 132 | else if([result isKindOfClass:[NSDictionary class]]) 133 | { 134 | NSDictionary *error = [result objectForKey:@"error"]; 135 | response.id = [result objectForKey:@"id"]; 136 | response.version = [result objectForKey:@"version"]; 137 | 138 | if(error && [error isKindOfClass:[NSDictionary class]]) 139 | response.error = [RPCError errorWithDictionary:error]; 140 | else 141 | response.result = [result objectForKey:@"result"]; 142 | } 143 | else 144 | response.error = [RPCError errorWithCode:RPCParseError]; 145 | } 146 | else 147 | response.error = [RPCError errorWithCode:RPCParseError]; 148 | } 149 | else 150 | response.error = [RPCError errorWithCode:RPCParseError]; 151 | 152 | return response; 153 | } 154 | 155 | #pragma mark - URL Connection delegates - 156 | 157 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 158 | { 159 | NSMutableData *rdata = [self.requestData objectForKey: [NSNumber numberWithInt:(int)connection]]; 160 | [rdata setLength:0]; 161 | } 162 | 163 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 164 | { 165 | NSMutableData *rdata = [self.requestData objectForKey: [NSNumber numberWithInt:(int)connection]]; 166 | [rdata appendData:data]; 167 | } 168 | 169 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection 170 | { 171 | NSMutableData *data = [self.requestData objectForKey: [NSNumber numberWithInt:(int)connection]]; 172 | NSArray *requests = [self.requests objectForKey: [NSNumber numberWithInt:(int)connection]]; 173 | 174 | [self handleData:data withRequests:requests]; 175 | 176 | [self.requestData removeObjectForKey: [NSNumber numberWithInt:(int)connection]]; 177 | [self.requests removeObjectForKey: [NSNumber numberWithInt:(int)connection]]; 178 | [connection release]; 179 | } 180 | 181 | - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 182 | { 183 | NSArray *requests = [self.requests objectForKey: [NSNumber numberWithInt:(int)connection]]; 184 | 185 | [self handleFailedRequests:requests withRPCError:[RPCError errorWithCode:RPCNetworkError]]; 186 | 187 | [self.requestData removeObjectForKey: [NSNumber numberWithInt:(int)connection]]; 188 | [self.requests removeObjectForKey: [NSNumber numberWithInt:(int)connection]]; 189 | [connection release]; 190 | } 191 | 192 | #pragma mark - Handling of data 193 | 194 | - (void) handleData:(NSData*)data withRequests:(NSArray*)requests 195 | { 196 | NSError *jsonError = nil; 197 | id results = [data objectFromJSONDataWithParseOptions:JKParseOptionNone error:&jsonError]; 198 | 199 | for(RPCRequest *request in requests) 200 | { 201 | if(request.callback == nil) 202 | continue; 203 | 204 | if(data.length == 0) 205 | request.callback([RPCResponse responseWithError:[RPCError errorWithCode:RPCServerError]]); 206 | else if(jsonError) 207 | request.callback([RPCResponse responseWithError:[RPCError errorWithCode:RPCParseError]]); 208 | else if([results isKindOfClass:[NSDictionary class]]) 209 | [self handleResult:results forRequest:request]; 210 | else if([results isKindOfClass:[NSArray class]]) 211 | { 212 | for(NSDictionary *result in results) 213 | { 214 | NSString *requestId = [result objectForKey:@"id"]; 215 | 216 | if([requestId isEqualToString:request.id]) 217 | { 218 | [self handleResult:result forRequest:request]; 219 | break; 220 | } 221 | } 222 | } 223 | } 224 | 225 | } 226 | 227 | - (void) handleFailedRequests:(NSArray*)requests withRPCError:(RPCError*)error 228 | { 229 | for(RPCRequest *request in requests) 230 | { 231 | if(request.callback == nil) 232 | continue; 233 | 234 | request.callback([RPCResponse responseWithError:error]); 235 | } 236 | 237 | } 238 | 239 | - (void) handleResult:(NSDictionary*) result forRequest:(RPCRequest*)request 240 | { 241 | if(!request.callback) 242 | return; 243 | 244 | NSString *requestId = [result objectForKey:@"id"]; 245 | 246 | NSDictionary *error = [result objectForKey:@"error"]; 247 | NSString *version = [result objectForKey:@"version"]; 248 | 249 | RPCResponse *response = [[RPCResponse alloc] init]; 250 | response.id = requestId; 251 | response.version = version; 252 | 253 | if(error && [error isKindOfClass:[NSDictionary class]]) 254 | response.error = [RPCError errorWithDictionary:error]; 255 | else 256 | response.result = [result objectForKey:@"result"]; 257 | 258 | request.callback(response); 259 | 260 | [response release]; 261 | } 262 | 263 | @end 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Helpers/JSONKit/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # JSONKit Changelog 2 | 3 | ## Version 1.X ????/??/?? 4 | 5 | **IMPORTANT:** The following changelog notes are a work in progress. They apply to the work done on JSONKit post v1.4. Since JSONKit itself is inbetween versions, these changelog notes are subject to change, may be wrong, and just about everything else you could expect at this point in development. 6 | 7 | ### New Features 8 | 9 | * When `JKSerializeOptionPretty` is enabled, JSONKit now sorts the keys. 10 | 11 | * Normally, JSONKit can only serialize NSNull, NSNumber, NSString, NSArray, and NSDictioonary like objects. It is now possible to serialize an object of any class via either a delegate or a `^` block. 12 | 13 | The delegate or `^` block must return an object that can be serialized by JSONKit, however, otherwise JSONKit will fail to serialize the object. In other words, JSONKit tries to serialize an unsupported class of the object just once, and if the delegate or ^block returns another unsupported class, the second attempt to serialize will fail. In practice, this is not a problem at all, but it does prevent endless recursive attempts to serialize an unsupported class. 14 | 15 | This makes it trivial to serialize objects like NSDate or NSData. A NSDate object can be formatted using a NSDateFormatter to return a ISO-8601 `YYYY-MM-DDTHH:MM:SS.sssZ` type object, for example. Or a NSData object could be Base64 encoded. 16 | 17 | This greatly simplifies things when you have a complex, nested objects with objects that do not belong to the classes that JSONKit can serialize. 18 | 19 | It should be noted that the same caching that JSONKit does for the supported class types also applies to the objects of an unsupported class- if the same object is serialized more than once and the object is still in the serialization cache, JSONKit will copy the previous serialization result instead of invoking the delegate or `^` block again. Therefore, you should not expect or depend on your delegate or block being called each time the same object needs to be serialized AND the delegate or block MUST return a "formatted object" that is STRICTLY invariant (that is to say the same object must always return the exact same formatted output). 20 | 21 | To serialize NSArray or NSDictionary objects using a delegate– 22 | 23 | **NOTE:** The delegate is based a single argument, the object with the unsupported class, and the supplied `selector` method must be one that accepts a single `id` type argument (i.e., `formatObject:`). 24 | **IMPORTANT:** The `^` block MUST return an object with a class that can be serialized by JSONKit, otherwise the serialization will fail. 25 | 26 |
 27 |     ​- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError \*\*)error;
 28 |     ​- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError \*\*)error;
 29 |     
30 | 31 | To serialize NSArray or NSDictionary objects using a `^` block– 32 | 33 | **NOTE:** The block is passed a single argument, the object with the unsupported class. 34 | **IMPORTANT:** The `^` block MUST return an object with a class that can be serialized by JSONKit, otherwise the serialization will fail. 35 | 36 |
 37 |     ​- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError \*\*)error;
 38 |     ​- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError \*\*)error;
 39 |     
40 | 41 | Example using the delegate way: 42 | 43 |
 44 |     @interface MYFormatter : NSObject {
 45 |       NSDateFormatter \*outputFormatter;
 46 |     }
 47 |     @end
 48 |     ​
 49 |     @implementation MYFormatter
 50 |     -(id)init
 51 |     {
 52 |       if((self = [super init]) == NULL) { return(NULL); }
 53 |       if((outputFormatter = [[NSDateFormatter alloc] init]) == NULL) { [self autorelease]; return(NULL); }
 54 |       [outputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"];
 55 |       return(self);
 56 |     }
 57 |     ​
 58 |     -(void)dealloc
 59 |     {
 60 |       if(outputFormatter != NULL) { [outputFormatter release]; outputFormatter = NULL; }
 61 |       [super dealloc];
 62 |     }
 63 |     ​
 64 |     -(id)formatObject:(id)object
 65 |     {
 66 |       if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); }
 67 |       return(NULL);
 68 |     }
 69 |     @end
 70 |     ​
 71 |     {
 72 |       MYFormatter \*myFormatter = [[[MYFormatter alloc] init] autorelease];
 73 |       NSArray \*array = [NSArray arrayWithObject:[NSDate dateWithTimeIntervalSinceNow:0.0]];
 74 | 
 75 |       NSString \*jsonString = NULL;
 76 |       jsonString = [array                    JSONStringWithOptions:JKSerializeOptionNone
 77 |                           serializeUnsupportedClassesUsingDelegate:myFormatter
 78 |                                                           selector:@selector(formatObject:)
 79 |                                                              error:NULL];
 80 |       NSLog(@"jsonString: '%@'", jsonString);
 81 |       // 2011-03-25 11:42:16.175 formatter_example[59120:903] jsonString: '["2011-03-25T11:42:16.175-0400"]'
 82 |     }
 83 |     
84 | 85 | Example using the `^` block way: 86 | 87 |
 88 |     {
 89 |       NSDateFormatter \*outputFormatter = [[[NSDateFormatter alloc] init] autorelease];
 90 |       [outputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"];
 91 |       ​
 92 |       jsonString = [array                 JSONStringWithOptions:encodeOptions
 93 |                           serializeUnsupportedClassesUsingBlock:^id(id object) {
 94 |                             if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); }
 95 |                             return(NULL);
 96 |                           }
 97 |                                                           error:NULL];
 98 |       NSLog(@"jsonString: '%@'", jsonString);
 99 |       // 2011-03-25 11:49:56.434 json_parse[59167:903] jsonString: '["2011-03-25T11:49:56.434-0400"]'
100 |     }
101 |     
102 | 103 | ### Major Changes 104 | 105 | * The way that JSONKit implements the collection classes was modified. Specifically, JSONKit now follows the same strategy that the Cocoa collection classes use, which is to have a single subclass of the mutable collection class. This concrete subclass has an ivar bit that determines whether or not that instance is mutable, and when an immutable instance receives a mutating message, it throws an exception. 106 | 107 | ## Version 1.4 2011/23/03 108 | 109 | ### Highlights 110 | 111 | * JSONKit v1.4 significantly improves the performance of serializing and deserializing. Deserializing is 23% faster than Apples binary `.plist`, and an amazing 549% faster than Apples binary `.plist` when serializing. 112 | 113 | ### New Features 114 | 115 | * JSONKit can now return mutable collection classes. 116 | * The `JKSerializeOptionFlags` option `JKSerializeOptionPretty` was implemented. 117 | * It is now possible to serialize a single [`NSString`][NSString]. This functionality was requested in issue #4 and issue #11. 118 | 119 | ### Deprecated Methods 120 | 121 | * The following `JSONDecoder` methods are deprecated beginning with JSONKit v1.4 and will be removed in a later release– 122 | 123 |
124 |     ​- (id)parseUTF8String:(const unsigned char \*)string length:(size_t)length;
125 |     ​- (id)parseUTF8String:(const unsigned char \*)string length:(size_t)length error:(NSError \*\*)error;
126 |     ​- (id)parseJSONData:(NSData \*)jsonData;
127 |     ​- (id)parseJSONData:(NSData \*)jsonData error:(NSError \*\*)error;
128 |     
129 | 130 | The JSONKit v1.4 objectWith… methods should be used instead. 131 | 132 | ### NEW API's 133 | 134 | * The following methods were added to `JSONDecoder`– 135 | 136 | These methods replace their deprecated parse… counterparts and return immutable collection objects. 137 | 138 |
139 |     ​- (id)objectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length;
140 |     ​- (id)objectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length error:(NSError \*\*)error;
141 |     ​- (id)objectWithData:(NSData \*)jsonData;
142 |     ​- (id)objectWithData:(NSData \*)jsonData error:(NSError \*\*)error;
143 |     
144 | 145 | These methods are the same as their objectWith… counterparts except they return mutable collection objects. 146 | 147 |
148 |     ​- (id)mutableObjectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length;
149 |     ​- (id)mutableObjectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length error:(NSError \*\*)error;
150 |     ​- (id)mutableObjectWithData:(NSData \*)jsonData;
151 |     ​- (id)mutableObjectWithData:(NSData \*)jsonData error:(NSError \*\*)error;
152 |     
153 | 154 | * The following methods were added to `NSString (JSONKitDeserializing)`– 155 | 156 | These methods are the same as their objectFrom… counterparts except they return mutable collection objects. 157 | 158 |
159 |     ​- (id)mutableObjectFromJSONString;
160 |     ​- (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
161 |     ​- (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError \*\*)error;
162 |     
163 | 164 | * The following methods were added to `NSData (JSONKitDeserializing)`– 165 | 166 | These methods are the same as their objectFrom… counterparts except they return mutable collection objects. 167 | 168 |
169 |     ​- (id)mutableObjectFromJSONData;
170 |     ​- (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
171 |     ​- (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError \*\*)error;
172 |     
173 | 174 | * The following methods were added to `NSString (JSONKitSerializing)`– 175 | 176 | These methods are for those uses that need to serialize a single [`NSString`][NSString]– 177 | 178 |
179 |     ​- (NSData \*)JSONData;
180 |     ​- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError \*\*)error;
181 |     ​- (NSString \*)JSONString;
182 |     ​- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError \*\*)error;
183 |     
184 | 185 | ### Bug Fixes 186 | 187 | * JSONKit has a fast and a slow path for parsing JSON Strings. The slow path is needed whenever special string processing is required, such as the conversion of `\` escape sequences or ill-formed UTF-8. Although the slow path had a check for characters < `0x20`, which are not permitted by the [RFC 4627][], there was a bug such that the condition was never actually checked. As a result, JSONKit would have incorrectly accepted JSON that contained characters < `0x20` if it was using the slow path to process a JSON String. 188 | * The low surrogate in a \uhigh\ulow escape sequence in a JSON String was incorrectly treating `dfff` as ill-formed Unicode. This was due to a comparison that used `>= 0xdfff` instead of `> 0xdfff` as it should have. 189 | * `JKParseOptionLooseUnicode` was not properly honored when parsing some types of ill-formed Unicode in \uHHHH escapes in JSON Strings. 190 | 191 | ### Important Notes 192 | 193 | * JSONKit v1.4 now uses custom concrete subclasses of [`NSArray`][NSArray], [`NSMutableArray`][NSMutableArray], [`NSDictionary`][NSDictionary], and [`NSMutableDictionary`][NSMutableDictionary]— `JKArray`, `JKMutableArray`, `JKDictionary`, and `JKMutableDictionary`. respectively. These classes are internal and private to JSONKit, you should not instantiate objects from these classes directly. 194 | 195 | In theory, these custom classes should behave exactly the same as the respective Foundation / Cocoa counterparts. 196 | 197 | As usual, in practice may have non-linear excursions from what theory predicts. It is also virtually impossible to properly test or predict how these custom classes will interact with software in the wild. 198 | 199 | Most likely, if you do encounter a problem, it will happen very quickly, and you should report a bug via the [github.com JSONKit Issue Tracker][bugtracker]. 200 | 201 | In addition to the required class cluster primitive methods, the custom collection classes also include support for [`NSFastEnumeration`][NSFastEnumeration], along with methods that support the bulk retrieval of the objects contents. 202 | 203 | #### Exceptions Thrown 204 | 205 | The JSONKit collection classes will throw the same exceptions for the same conditions as their respective Foundation counterparts. If you find a discrepancy, please report a bug via the [github.com JSONKit Issue Tracker][bugtracker]. 206 | 207 | #### Multithreading Safety 208 | 209 | The same multithreading rules and caveats for the Foundation collection classes apply to the JSONKit collection classes. Specifically, it should be safe to use the immutable collections from multiple threads concurrently. 210 | 211 | The mutable collections can be used from multiple threads as long as you provide some form of mutex barrier that ensures that if a thread needs to mutate the collection, then it has exclusive access to the collection– no other thread can be reading from or writing to the collection until the mutating thread has finished. Failure to ensure that there are no other threads reading or writing from the mutable collection when a thread mutates the collection will result in `undefined` behavior. 212 | 213 | #### Mutable Collection Notes 214 | 215 | The mutable versions of the collection classes are meant to be used when you need to make minor modifications to the collection. Neither `JKMutableArray` or `JKMutableDictionary` have been optimized for nor are they intended to be used in situations where you are adding a large number of objects or new keys– these types of operations will cause both classes to frequently reallocate the memory used to hold the objects in the collection. 216 | 217 | #### `JKMutableArray` Usage Notes 218 | 219 | * You should minimize the number of new objects you added to the array. The array is not designed for high performance insertion and removal of objects. If the array does not have any extra capacity it must reallocate the backing store. When the array is forced to grow the backing store, it currently adds an additional 16 slots worth of spare capacity. The array is instantiated without any extra capacity on the assumption that dictionaries are going to be mutated more than arrays. The array never shrinks the backing store. 220 | 221 | * Replacing objects in the array via [`-replaceObjectAtIndex:withObject:`][-replaceObjectAtIndex:withObject:] is very fast since the array simply releases the current object at the index and replaces it with the new object. 222 | 223 | * Inserting an object in to the array via [`-insertObject:atIndex:`][-insertObject:atIndex:] cause the array to [`memmove()`][memmove] all the objects up one slot from the insertion index. This means this operation is fastest when inserting objects at the last index since no objects need to be moved. 224 | 225 | * Removing an object from the array via [`-removeObjectAtIndex:`][-removeObjectAtIndex:] causes the array to [`memmove()`][memmove] all the objects down one slot from the removal index. This means this operation is fastest when removing objects at the last index since no objects need to be moved. The array will not resize its backing store to a smaller size. 226 | 227 | * [`-copy`][-copy] and [`-mutableCopy`][-mutableCopy] will instantiate a new [`NSArray`][NSArray] or [`NSMutableArray`][NSMutableArray] class object, respectively, with the contents of the receiver. 228 | 229 | #### `JKMutableDictionary` Usage Notes 230 | 231 | * You should minimize the number of new keys you add to the dictionary. If the number of items in the dictionary exceeds a threshold value it will trigger a resizing operation. To do this, the dictionary must allocate a new, larger backing store, and then re-add all the items in the dictionary by rehashing them to the size of the newer, larger store. This is an expensive operation. While this is a limitation of nearly all hash tables, the capacity for the hash table used by `JKMutableDictionary` has been chosen to minimize the amount of memory used since it is anticipated that most dictionaries will not grow significantly once they are instantiated. 232 | 233 | * If the key already exists in the dictionary and you change the object associated with it via [`-setObject:forKey:`][-setObject:forKey:], this will not cause any performance problems or trigger a hash table resize. 234 | 235 | * Removing a key from the dictionary via [`-removeObjectForKey:`][-removeObjectForKey:] will not cause any performance problems. However, the dictionary will not resize its backing store to the smaller size. 236 | 237 | * [`-copy`][-copy] and [`-mutableCopy`][-mutableCopy] will instantiate a new [`NSDictionary`][NSDictionary] or [`NSMutableDictionary`][NSMutableDictionary] class object, respectively, with the contents of the receiver. 238 | 239 | ### Major Changes 240 | 241 | * The `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` pre-processor define flag that was added to JSONKit v1.3 has been removed. 242 | 243 | `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` was added in JSONKit v1.3 as a temporary work around. While the author was aware of other ways to fix the particular problem caused by the usage of "transfer of ownership callbacks" with Core Foundation classes, the fix provided in JSONKit v1.3 was trivial to implement. This allowed people who needed that functionality to use JSONKit while a proper solution to the problem was worked on. JSONKit v1.4 is the result of that work. 244 | 245 | JSONKit v1.4 no longer uses the Core Foundation collection classes [`CFArray`][CFArray] and [`CFDictionary`][CFDictionary]. Instead, JSONKit v1.4 contains a concrete subclass of [`NSArray`][NSArray] and [`NSDictionary`][NSDictionary]– `JKArray` and `JKDictionary`, respectively. As a result, JSONKit has complete control over the behavior of how items are added and managed within an instantiated collection object. The `JKArray` and `JKDictionary` classes are private to JSONKit, you should not instantiate them direction. Since they are concrete subclasses of their respective collection class cluster, they behave and act exactly the same as [`NSArray`][NSArray] and [`NSDictionary`][NSDictionary]. 246 | 247 | The first benefit is that the "transfer of ownership" object ownership policy can now be safely used. Because the JSONKit collection objects understand that some methods, such as [`-mutableCopy`][-mutableCopy], should not inherit the same "transfer of ownership" object ownership policy, but must follow the standard Cocoa object ownership policy. The "transfer of ownership" object ownership policy reduces the number of [`-retain`][-retain] and [`-release`][-release] calls needed to add an object to a collection, and when creating a large number of objects very quickly (as you would expect when parsing JSON), this can result in a non-trivial amount of time. Eliminating these calls means faster JSON parsing. 248 | 249 | A second benefit is that the author encountered some unexpected behavior when using the [`CFDictionaryCreate`][CFDictionaryCreate] function to create a dictionary and the `keys` argument contained duplicate keys. This required JSONKit to de-duplicate the keys and values before calling [`CFDictionaryCreate`][CFDictionaryCreate]. Unfortunately, JSONKit always had to scan all the keys to make sure there were no duplicates, even though 99.99% of the time there were none. This was less than optimal, particularly because one of the solutions to this particular problem is to use a hash table to perform the de-duplication. Now JSONKit can do the de-duplication while it is instantiating the dictionary collection, solving two problems at once. 250 | 251 | Yet another benefit is that the recently instantiated object cache that JSONKit uses can be used to cache information about the keys used to create dictionary collections, in particular a keys [`-hash`][-hash] value. For a lot of real world JSON, this effectively means that the [`-hash`][-hash] for a key is calculated once, and that value is reused again and again when creating dictionaries. Because all the information required to create the hash table used by `JKDictionary` is already determined at the time the `JKDictionary` object is instantiated, populating the `JKDictionary` is now a very tight loop that only has to call [`-isEqual:`][-isEqual:] on the rare occasions that the JSON being parsed contains duplicate keys. Since the functions that handle this logic are all declared `static` and are internal to JSONKit, the compiler can heavily optimize this code. 252 | 253 | What does this mean in terms of performance? JSONKit was already fast, but now, it's even faster. Below is some benchmark times for [`twitter_public_timeline.json`][twitter_public_timeline.json] in [samsoffes / json-benchmarks](https://github.com/samsoffes/json-benchmarks), where _read_ means to convert the JSON to native Objective-C objects, and _write_ means to convert the native Objective-C to JSON— 254 | 255 |
256 |     v1.3 read : min:  456.000 us, avg:  460.056 us, char/s:  53341332.36 /  50.870 MB/s
257 |     v1.3 write: min:  150.000 us, avg:  151.816 us, char/s: 161643041.58 / 154.155 MB/s
258 | 259 |
260 |     v1.4 read : min:  285.000 us, avg:  288.603 us, char/s:  85030301.14 /  81.091 MB/s
261 |     v1.4 write: min:  127.000 us, avg:  129.617 us, char/s: 189327017.29 / 180.556 MB/s
262 | 263 | JSONKit v1.4 is nearly 60% faster at reading and 17% faster at writing than v1.3. 264 | 265 | The following is the JSON test file taken from the project available at [this blog post](http://psionides.jogger.pl/2010/12/12/cocoa-json-parsing-libraries-part-2/). The keys and information contained in the JSON was anonymized with random characters. Since JSONKit relies on its recently instantiated object cache for a lot of its performance, this JSON happens to be "the worst corner case possible". 266 | 267 |
268 |     v1.3 read : min: 5222.000 us, avg: 5262.344 us, char/s:  15585260.10 /  14.863 MB/s
269 |     v1.3 write: min: 1253.000 us, avg: 1259.914 us, char/s:  65095712.88 /  62.080 MB/s
270 | 271 |
272 |     v1.4 read : min: 4096.000 us, avg: 4122.240 us, char/s:  19895736.30 /  18.974 MB/s
273 |     v1.4 write: min: 1319.000 us, avg: 1335.538 us, char/s:  61409709.05 /  58.565 MB/s
274 | 275 | JSONKit v1.4 is 28% faster at reading and 6% faster at writing that v1.3 in this worst-case torture test. 276 | 277 | While your milage may vary, you will likely see improvements in the 50% for reading and 10% for writing on your real world JSON. The nature of JSONKits cache means performance improvements is statistical in nature and depends on the particular properties of the JSON being parsed. 278 | 279 | For comparison, [json-framework][], a popular Objective-C JSON parsing library, turns in the following benchmark times for [`twitter_public_timeline.json`][twitter_public_timeline.json]— 280 | 281 |
282 |     ​     read : min: 1670.000 us, avg: 1682.461 us, char/s:  14585776.43 /  13.910 MB/s
283 |     ​     write: min: 1021.000 us, avg: 1028.970 us, char/s:  23849091.81 /  22.744 MB/s
284 | 285 | Since the benchmark for JSONKit and [json-framework][] was done on the same computer, it's safe to compare the timing results. The version of [json-framework][] used was the latest v3.0 available via the master branch at the time of this writing on github.com. 286 | 287 | JSONKit v1.4 is 483% faster at reading and 694% faster at writing than [json-framework][]. 288 | 289 | ### Other Changes 290 | 291 | * Added a `__clang_analyzer__` pre-processor conditional around some code that the `clang` static analyzer was giving false positives for. However, `clang` versions ≤ 1.5 do not define `__clang_analyzer__` and therefore will continue to emit analyzer warnings. 292 | * The cache now uses a Galois Linear Feedback Shift Register PRNG to select which item in the cache to randomly age. This should age items in the cache more fairly. 293 | * To promote better L1 cache locality, the cache age structure was rearranged slightly along with modifying when an item is randomly chosen to be aged. 294 | * Removed a lot of internal and private data structures from `JSONKit.h` and put them in `JSONKit.m`. 295 | * Modified the way floating point values are serialized. Previously, the [`printf`][printf] format conversion `%.16g` was used. This was changed to `%.17g` which should theoretically allow for up to a full `float`, or [IEEE 754 Single 32-bit floating-point][Single Precision], of precision when converting floating point values to decimal representation. 296 | * The usual sundry of inconsequential tidies and what not, such as updating the `README.md`, etc. 297 | * The catagory additions to the Cocoa classes were changed from `JSONKit` to `JSONKitDeserializing` and `JSONKitSerializing`, as appropriate. 298 | 299 | ## Version 1.3 2011/05/02 300 | 301 | ### New Features 302 | 303 | * Added the `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` pre-processor define flag. 304 | 305 | This is typically enabled by adding `-DJK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` to the compilers command line arguments or in `Xcode.app` by adding `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` to a projects / targets `Pre-Processor Macros` settings. 306 | 307 | The `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` option enables the use of custom Core Foundation collection call backs which omit the [`CFRetain`][CFRetain] calls. This results in saving several [`CFRetain`][CFRetain] and [`CFRelease`][CFRelease] calls typically needed for every single object from the parsed JSON. While the author has used this technique for years without any issues, an unexpected interaction with the Foundation [`-mutableCopy`][-mutableCopy] method and Core Foundation Toll-Free Bridging resulting in a condition in which the objects contained in the collection to be over released. This problem does not occur with the use of [`-copy`][-copy] due to the fact that the objects created by JSONKit are immutable, and therefore [`-copy`][-copy] does not require creating a completely new object and copying the contents, instead [`-copy`][-copy] simply returns a [`-retain`][-retain]'d version of the immutable object which is significantly faster along with the obvious reduction in memory usage. 308 | 309 | Prior to version 1.3, JSONKit always used custom "Transfer of Ownership Collection Callbacks", and thus `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` was effectively implicitly defined. 310 | 311 | Beginning with version 1.3, the default behavior of JSONKit is to use the standard Core Foundation collection callbacks ([`kCFTypeArrayCallBacks`][kCFTypeArrayCallBacks], [`kCFTypeDictionaryKeyCallBacks`][kCFTypeDictionaryKeyCallBacks], and [`kCFTypeDictionaryValueCallBacks`][kCFTypeDictionaryValueCallBacks]). The intention is to follow "the principle of least surprise", and the author believes the use of the standard Core Foundation collection callbacks as the default behavior for JSONKit results in the least surprise. 312 | 313 | **NOTE**: `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` is only applicable to `(CF|NS)` `Dictionary` and `Array` class objects. 314 | 315 | For the vast majority of users, the author believes JSONKits custom "Transfer of Ownership Collection Callbacks" will not cause any problems. As previously stated, the author has used this technique in performance critical code for years and has never had a problem. Until a user reported a problem with [`-mutableCopy`][-mutableCopy], the author was unaware that the use of the custom callbacks could even cause a problem. This is probably due to the fact that the vast majority of time the typical usage pattern tends to be "iterate the contents of the collection" and very rarely mutate the returned collection directly (although this last part is likely to vary significantly from programmer to programmer). The author tends to avoid the use of [`-mutableCopy`][-mutableCopy] as it results in a significant performance and memory consumption penalty. The reason for this is in "typical" Cocoa coding patterns, using [`-mutableCopy`][-mutableCopy] will instantiate an identical, albeit mutable, version of the original object. This requires both memory for the new object and time to iterate the contents of the original object and add them to the new object. Furthermore, under "typical" Cocoa coding patterns, the original collection object continues to consume memory until the autorelease pool is released. However, clearly there are cases where the use of [`-mutableCopy`][-mutableCopy] makes sense or may be used by an external library which is out of your direct control. 316 | 317 | The use of the standard Core Foundation collection callbacks results in a 9% to 23% reduction in parsing performance, with an "eye-balled average" of around 13% according to some benchmarking done by the author using Real World™ JSON (i.e., actual JSON from various web services, such as Twitter, etc) using `gcc-4.2 -arch x86_64 -O3 -DNS_BLOCK_ASSERTIONS` with the only change being the addition of `-DJK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS`. 318 | 319 | `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` is only applicable to parsing / deserializing (i.e. converting from) of JSON. Serializing (i.e., converting to JSON) is completely unaffected by this change. 320 | 321 | ### Bug Fixes 322 | 323 | * Fixed a [bug report regarding `-mutableCopy`](https://github.com/johnezang/JSONKit/issues#issue/3). This is related to the addition of the pre-processor define flag `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS`. 324 | 325 | ### Other Changes 326 | 327 | * Added `JK_EXPECTED` optimization hints around several conditionals. 328 | * When serializing objects, JSONKit first starts with a small, on stack buffer. If the encoded JSON exceeds the size of the stack buffer, JSONKit switches to a heap allocated buffer. If JSONKit switched to a heap allocated buffer, [`CFDataCreateWithBytesNoCopy`][CFDataCreateWithBytesNoCopy] is used to create the [`NSData`][NSData] object, which in most cases causes the heap allocated buffer to "transfer" to the [`NSData`][NSData] object which is substantially faster than allocating a new buffer and copying the bytes. 329 | * Added a pre-processor check in `JSONKit.m` to see if Objective-C Garbage Collection is enabled and issue a `#error` notice that JSONKit does not support Objective-C Garbage Collection. 330 | * Various other minor or trivial modifications, such as updating `README.md`. 331 | 332 | ### Other Issues 333 | 334 | * When using the `clang` static analyzer (the version used at the time of this writing was `Apple clang version 1.5 (tags/Apple/clang-60)`), the static analyzer reports a number of problems with `JSONKit.m`. 335 | 336 | The author has investigated these issues and determined that the problems reported by the current version of the static analyzer are "false positives". Not only that, the reported problems are not only "false positives", they are very clearly and obviously wrong. Therefore, the author has made the decision that no action will be taken on these non-problems, which includes not modifying the code for the sole purpose of silencing the static analyzer. The justification for this is "the dog wags the tail, not the other way around." 337 | 338 | ## Version 1.2 2011/01/08 339 | 340 | ### Bug Fixes 341 | 342 | * When JSONKit attempted to parse and decode JSON that contained `{"key": value}` dictionaries that contained the same key more than once would likely result in a crash. This was a serious bug. 343 | * Under some conditions, JSONKit could potentially leak memory. 344 | * There was an off by one error in the code that checked whether or not the parser was at the end of the `UTF8` buffer. This could result in JSONKit reading one by past the buffer bounds in some cases. 345 | 346 | ### Other Changes 347 | 348 | * Some of the methods were missing `NULL` pointer checks for some of their arguments. This was fixed. In generally, when JSONKit encounters invalid arguments, it throws a `NSInvalidArgumentException` exception. 349 | * Various other minor changes such as tightening up numeric literals with `UL` or `L` qualification, assertion check tweaks and additions, etc. 350 | * The README.md file was updated with additional information. 351 | 352 | ### Version 1.1 353 | 354 | No change log information was kept for versions prior to 1.2. 355 | 356 | [bugtracker]: https://github.com/johnezang/JSONKit/issues 357 | [RFC 4627]: http://tools.ietf.org/html/rfc4627 358 | [twitter_public_timeline.json]: https://github.com/samsoffes/json-benchmarks/blob/master/Resources/twitter_public_timeline.json 359 | [json-framework]: https://github.com/stig/json-framework 360 | [Single Precision]: http://en.wikipedia.org/wiki/Single_precision 361 | [kCFTypeArrayCallBacks]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html#//apple_ref/c/data/kCFTypeArrayCallBacks 362 | [kCFTypeDictionaryKeyCallBacks]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/data/kCFTypeDictionaryKeyCallBacks 363 | [kCFTypeDictionaryValueCallBacks]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/data/kCFTypeDictionaryValueCallBacks 364 | [CFRetain]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFTypeRef/Reference/reference.html#//apple_ref/c/func/CFRetain 365 | [CFRelease]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFTypeRef/Reference/reference.html#//apple_ref/c/func/CFRelease 366 | [CFDataCreateWithBytesNoCopy]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDataRef/Reference/reference.html#//apple_ref/c/func/CFDataCreateWithBytesNoCopy 367 | [CFArray]: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html 368 | [CFDictionary]: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html 369 | [CFDictionaryCreate]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/func/CFDictionaryCreate 370 | [-mutableCopy]: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSObject/mutableCopy 371 | [-copy]: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSObject/copy 372 | [-retain]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/retain 373 | [-release]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/release 374 | [-isEqual:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/isEqual: 375 | [-hash]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/hash 376 | [NSArray]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html 377 | [NSMutableArray]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/index.html 378 | [-insertObject:atIndex:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/insertObject:atIndex: 379 | [-removeObjectAtIndex:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/removeObjectAtIndex: 380 | [-replaceObjectAtIndex:withObject:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/replaceObjectAtIndex:withObject: 381 | [NSDictionary]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/index.html 382 | [NSMutableDictionary]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/index.html 383 | [-setObject:forKey:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/setObject:forKey: 384 | [-removeObjectForKey:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/removeObjectForKey: 385 | [NSData]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/index.html 386 | [NSFastEnumeration]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSFastEnumeration_protocol/Reference/NSFastEnumeration.html 387 | [NSString]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html 388 | [printf]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/printf.3.html 389 | [memmove]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/memmove.3.html 390 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Helpers/JSONKit/JSONKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONKit.h 3 | // http://github.com/johnezang/JSONKit 4 | // Dual licensed under either the terms of the BSD License, or alternatively 5 | // under the terms of the Apache License, Version 2.0, as specified below. 6 | // 7 | 8 | /* 9 | Copyright (c) 2011, John Engelhart 10 | 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright 17 | notice, this list of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright 20 | notice, this list of conditions and the following disclaimer in the 21 | documentation and/or other materials provided with the distribution. 22 | 23 | * Neither the name of the Zang Industries nor the names of its 24 | contributors may be used to endorse or promote products derived from 25 | this software without specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 33 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* 41 | Copyright 2011 John Engelhart 42 | 43 | Licensed under the Apache License, Version 2.0 (the "License"); 44 | you may not use this file except in compliance with the License. 45 | You may obtain a copy of the License at 46 | 47 | http://www.apache.org/licenses/LICENSE-2.0 48 | 49 | Unless required by applicable law or agreed to in writing, software 50 | distributed under the License is distributed on an "AS IS" BASIS, 51 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 | See the License for the specific language governing permissions and 53 | limitations under the License. 54 | */ 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | #ifdef __OBJC__ 63 | #import 64 | #import 65 | #import 66 | #import 67 | #import 68 | #import 69 | #endif // __OBJC__ 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | 76 | // For Mac OS X < 10.5. 77 | #ifndef NSINTEGER_DEFINED 78 | #define NSINTEGER_DEFINED 79 | #if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) 80 | typedef long NSInteger; 81 | typedef unsigned long NSUInteger; 82 | #define NSIntegerMin LONG_MIN 83 | #define NSIntegerMax LONG_MAX 84 | #define NSUIntegerMax ULONG_MAX 85 | #else // defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) 86 | typedef int NSInteger; 87 | typedef unsigned int NSUInteger; 88 | #define NSIntegerMin INT_MIN 89 | #define NSIntegerMax INT_MAX 90 | #define NSUIntegerMax UINT_MAX 91 | #endif // defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) 92 | #endif // NSINTEGER_DEFINED 93 | 94 | 95 | #ifndef _JSONKIT_H_ 96 | #define _JSONKIT_H_ 97 | 98 | #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__APPLE_CC__) && (__APPLE_CC__ >= 5465) 99 | #define JK_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) 100 | #else 101 | #define JK_DEPRECATED_ATTRIBUTE 102 | #endif 103 | 104 | #define JSONKIT_VERSION_MAJOR 1 105 | #define JSONKIT_VERSION_MINOR 4 106 | 107 | typedef NSUInteger JKFlags; 108 | 109 | /* 110 | JKParseOptionComments : Allow C style // and /_* ... *_/ (without a _, obviously) comments in JSON. 111 | JKParseOptionUnicodeNewlines : Allow Unicode recommended (?:\r\n|[\n\v\f\r\x85\p{Zl}\p{Zp}]) newlines. 112 | JKParseOptionLooseUnicode : Normally the decoder will stop with an error at any malformed Unicode. 113 | This option allows JSON with malformed Unicode to be parsed without reporting an error. 114 | Any malformed Unicode is replaced with \uFFFD, or "REPLACEMENT CHARACTER". 115 | */ 116 | 117 | enum { 118 | JKParseOptionNone = 0, 119 | JKParseOptionStrict = 0, 120 | JKParseOptionComments = (1 << 0), 121 | JKParseOptionUnicodeNewlines = (1 << 1), 122 | JKParseOptionLooseUnicode = (1 << 2), 123 | JKParseOptionPermitTextAfterValidJSON = (1 << 3), 124 | JKParseOptionValidFlags = (JKParseOptionComments | JKParseOptionUnicodeNewlines | JKParseOptionLooseUnicode | JKParseOptionPermitTextAfterValidJSON), 125 | }; 126 | typedef JKFlags JKParseOptionFlags; 127 | 128 | enum { 129 | JKSerializeOptionNone = 0, 130 | JKSerializeOptionPretty = (1 << 0), 131 | JKSerializeOptionEscapeUnicode = (1 << 1), 132 | JKSerializeOptionEscapeForwardSlashes = (1 << 4), 133 | JKSerializeOptionValidFlags = (JKSerializeOptionPretty | JKSerializeOptionEscapeUnicode | JKSerializeOptionEscapeForwardSlashes), 134 | }; 135 | typedef JKFlags JKSerializeOptionFlags; 136 | 137 | #ifdef __OBJC__ 138 | 139 | typedef struct JKParseState JKParseState; // Opaque internal, private type. 140 | 141 | // As a general rule of thumb, if you use a method that doesn't accept a JKParseOptionFlags argument, it defaults to JKParseOptionStrict 142 | 143 | @interface JSONDecoder : NSObject { 144 | JKParseState *parseState; 145 | } 146 | + (id)decoder; 147 | + (id)decoderWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 148 | - (id)initWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 149 | - (void)clearCache; 150 | 151 | // The parse... methods were deprecated in v1.4 in favor of the v1.4 objectWith... methods. 152 | - (id)parseUTF8String:(const unsigned char *)string length:(size_t)length JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithUTF8String:length: instead. 153 | - (id)parseUTF8String:(const unsigned char *)string length:(size_t)length error:(NSError **)error JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithUTF8String:length:error: instead. 154 | // The NSData MUST be UTF8 encoded JSON. 155 | - (id)parseJSONData:(NSData *)jsonData JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithData: instead. 156 | - (id)parseJSONData:(NSData *)jsonData error:(NSError **)error JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithData:error: instead. 157 | 158 | // Methods that return immutable collection objects. 159 | - (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length; 160 | - (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error; 161 | // The NSData MUST be UTF8 encoded JSON. 162 | - (id)objectWithData:(NSData *)jsonData; 163 | - (id)objectWithData:(NSData *)jsonData error:(NSError **)error; 164 | 165 | // Methods that return mutable collection objects. 166 | - (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length; 167 | - (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error; 168 | // The NSData MUST be UTF8 encoded JSON. 169 | - (id)mutableObjectWithData:(NSData *)jsonData; 170 | - (id)mutableObjectWithData:(NSData *)jsonData error:(NSError **)error; 171 | 172 | @end 173 | 174 | //////////// 175 | #pragma mark Deserializing methods 176 | //////////// 177 | 178 | @interface NSString (JSONKitDeserializing) 179 | - (id)objectFromJSONString; 180 | - (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 181 | - (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 182 | - (id)mutableObjectFromJSONString; 183 | - (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 184 | - (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 185 | @end 186 | 187 | @interface NSData (JSONKitDeserializing) 188 | // The NSData MUST be UTF8 encoded JSON. 189 | - (id)objectFromJSONData; 190 | - (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 191 | - (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 192 | - (id)mutableObjectFromJSONData; 193 | - (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 194 | - (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 195 | @end 196 | 197 | //////////// 198 | #pragma mark Serializing methods 199 | //////////// 200 | 201 | @interface NSString (JSONKitSerializing) 202 | // Convenience methods for those that need to serialize the receiving NSString (i.e., instead of having to serialize a NSArray with a single NSString, you can "serialize to JSON" just the NSString). 203 | // Normally, a string that is serialized to JSON has quotation marks surrounding it, which you may or may not want when serializing a single string, and can be controlled with includeQuotes: 204 | // includeQuotes:YES `a "test"...` -> `"a \"test\"..."` 205 | // includeQuotes:NO `a "test"...` -> `a \"test\"...` 206 | - (NSData *)JSONData; // Invokes JSONDataWithOptions:JKSerializeOptionNone includeQuotes:YES 207 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error; 208 | - (NSString *)JSONString; // Invokes JSONStringWithOptions:JKSerializeOptionNone includeQuotes:YES 209 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error; 210 | @end 211 | 212 | @interface NSArray (JSONKitSerializing) 213 | - (NSData *)JSONData; 214 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 215 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 216 | - (NSString *)JSONString; 217 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 218 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 219 | @end 220 | 221 | @interface NSDictionary (JSONKitSerializing) 222 | - (NSData *)JSONData; 223 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 224 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 225 | - (NSString *)JSONString; 226 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 227 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error; 228 | @end 229 | 230 | #ifdef __BLOCKS__ 231 | 232 | @interface NSArray (JSONKitSerializingBlockAdditions) 233 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 234 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 235 | @end 236 | 237 | @interface NSDictionary (JSONKitSerializingBlockAdditions) 238 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 239 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error; 240 | @end 241 | 242 | #endif 243 | 244 | 245 | #endif // __OBJC__ 246 | 247 | #endif // _JSONKIT_H_ 248 | 249 | #ifdef __cplusplus 250 | } // extern "C" 251 | #endif 252 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Helpers/JSONKit/README.md: -------------------------------------------------------------------------------- 1 | # JSONKit 2 | 3 | JSONKit is dual licensed under either the terms of the BSD License, or alternatively under the terms of the Apache License, Version 2.0.
4 | Copyright © 2011, John Engelhart. 5 | 6 | ### A Very High Performance Objective-C JSON Library 7 | 8 | **UPDATE:** (2011/12/18) The benchmarks below were performed before Apples [`NSJSONSerialization`][NSJSONSerialization] was available (as of Mac OS X 10.7 and iOS 5). The obvious question is: Which is faster, [`NSJSONSerialization`][NSJSONSerialization] or JSONKit? According to [this site](http://www.bonto.ch/blog/2011/12/08/json-libraries-for-ios-comparison-updated/), JSONKit is faster than [`NSJSONSerialization`][NSJSONSerialization]. Some quick "back of the envelope" calculations using the numbers reported, JSONKit appears to be approximately 25% to 40% faster than [`NSJSONSerialization`][NSJSONSerialization], which is pretty significant. 9 | 10 | Parsing | Serializing 11 | :---------:|:-------------: 12 | Deserialize from JSON | Serialize to JSON 13 | *23% Faster than Binary* .plist* !* | *549% Faster than Binary* .plist* !* 14 | 15 | * Benchmarking was performed on a MacBook Pro with a 2.66GHz Core 2. 16 | * All JSON libraries were compiled with `gcc-4.2 -DNS_BLOCK_ASSERTIONS -O3 -arch x86_64`. 17 | * Timing results are the average of 1,000 iterations of the user + system time reported by [`getrusage`][getrusage]. 18 | * The JSON used was [`twitter_public_timeline.json`](https://github.com/samsoffes/json-benchmarks/blob/master/Resources/twitter_public_timeline.json) from [samsoffes / json-benchmarks](https://github.com/samsoffes/json-benchmarks). 19 | * Since the `.plist` format does not support serializing [`NSNull`][NSNull], the `null` values in the original JSON were changed to `"null"`. 20 | * The [experimental](https://github.com/johnezang/JSONKit/tree/experimental) branch contains the `gzip` compression changes. 21 | * JSONKit automagically links to `libz.dylib` on the fly at run time– no manual linking required. 22 | * Parsing / deserializing will automagically decompress a buffer if it detects a `gzip` signature header. 23 | * You can compress / `gzip` the serialized JSON by passing `JKSerializeOptionCompress` to `-JSONDataWithOptions:error:`. 24 | 25 | [JSON versus PLIST, the Ultimate Showdown](http://www.cocoanetics.com/2011/03/json-versus-plist-the-ultimate-showdown/) benchmarks the common JSON libraries and compares them to Apples `.plist` format. 26 | 27 | *** 28 | 29 | JavaScript Object Notation, or [JSON][], is a lightweight, text-based, serialization format for structured data that is used by many web-based services and API's. It is defined by [RFC 4627][]. 30 | 31 | JSON provides the following primitive types: 32 | 33 | * `null` 34 | * Boolean `true` and `false` 35 | * Number 36 | * String 37 | * Array 38 | * Object (a.k.a. Associative Arrays, Key / Value Hash Tables, Maps, Dictionaries, etc.) 39 | 40 | These primitive types are mapped to the following Objective-C Foundation classes: 41 | 42 | JSON | Objective-C 43 | -------------------|------------- 44 | `null` | [`NSNull`][NSNull] 45 | `true` and `false` | [`NSNumber`][NSNumber] 46 | Number | [`NSNumber`][NSNumber] 47 | String | [`NSString`][NSString] 48 | Array | [`NSArray`][NSArray] 49 | Object | [`NSDictionary`][NSDictionary] 50 | 51 | JSONKit uses Core Foundation internally, and it is assumed that Core Foundation ≡ Foundation for every equivalent base type, i.e. [`CFString`][CFString] ≡ [`NSString`][NSString]. 52 | 53 | The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119][]. 54 | 55 | ### JSON To Objective-C Primitive Mapping Details 56 | 57 | * The [JSON specification][RFC 4627] is somewhat ambiguous about the details and requirements when it comes to Unicode, and it does not specify how Unicode issues and errors should be handled. Most of the ambiguity stems from the interpretation and scope [RFC 4627][] Section 3, Encoding: `JSON text SHALL be encoded in Unicode.` It is the authors opinion and interpretation that the language of [RFC 4627][] requires that a JSON implementation MUST follow the requirements specified in the [Unicode Standard][], and in particular the [Conformance][Unicode Standard - Conformance] chapter of the [Unicode Standard][], which specifies requirements related to handling, interpreting, and manipulating Unicode text. 58 | 59 | The default behavior for JSONKit is strict [RFC 4627][] conformance. It is the authors opinion and interpretation that [RFC 4627][] requires JSON to be encoded in Unicode, and therefore JSON that is not legal Unicode as defined by the [Unicode Standard][] is invalid JSON. Therefore, JSONKit will not accept JSON that contains ill-formed Unicode. The default, strict behavior implies that the `JKParseOptionLooseUnicode` option is not enabled. 60 | 61 | When the `JKParseOptionLooseUnicode` option is enabled, JSONKit follows the specifications and recommendations given in [The Unicode 6.0 standard, Chapter 3 - Conformance][Unicode Standard - Conformance], section 3.9 *Unicode Encoding Forms*. As a general rule of thumb, the Unicode code point `U+FFFD` is substituted for any ill-formed Unicode encountered. JSONKit attempts to follow the recommended *Best Practice for Using U+FFFD*: ***Replace each maximal subpart of an ill-formed subsequence by a single U+FFFD.*** 62 | 63 | The following Unicode code points are treated as ill-formed Unicode, and if `JKParseOptionLooseUnicode` is enabled, cause `U+FFFD` to be substituted in their place: 64 | 65 | `U+0000`.
66 | `U+D800` thru `U+DFFF`, inclusive.
67 | `U+FDD0` thru `U+FDEF`, inclusive.
68 | U+nFFFE and U+nFFFF, where *n* is from `0x0` to `0x10` 69 | 70 | The code points `U+FDD0` thru `U+FDEF`, U+nFFFE, and U+nFFFF (where *n* is from `0x0` to `0x10`), are defined as ***Noncharacters*** by the Unicode standard and "should never be interchanged". 71 | 72 | An exception is made for the code point `U+0000`, which is legal Unicode. The reason for this is that this particular code point is used by C string handling code to specify the end of the string, and any such string handling code will incorrectly stop processing a string at the point where `U+0000` occurs. Although reasonable people may have different opinions on this point, it is the authors considered opinion that the risks of permitting JSON Strings that contain `U+0000` outweigh the benefits. One of the risks in allowing `U+0000` to appear unaltered in a string is that it has the potential to create security problems by subtly altering the semantics of the string which can then be exploited by a malicious attacker. This is similar to the issue of [arbitrarily deleting characters from Unicode text][Unicode_UTR36_Deleting]. 73 | 74 | [RFC 4627][] allows for these limitations under section 4, Parsers: `An implementation may set limits on the length and character contents of strings.` While the [Unicode Standard][] permits the mutation of the original JSON (i.e., substituting `U+FFFD` for ill-formed Unicode), [RFC 4627][] is silent on this issue. It is the authors opinion and interpretation that [RFC 4627][], section 3 – *Encoding*, `JSON text SHALL be encoded in Unicode.` implies that such mutations are not only permitted but MUST be expected by any strictly conforming [RFC 4627][] JSON implementation. The author feels obligated to note that this opinion and interpretation may not be shared by others and, in fact, may be a minority opinion and interpretation. You should be aware that any mutation of the original JSON may subtly alter its semantics and, as a result, may have security related implications for anything that consumes the final result. 75 | 76 | It is important to note that JSONKit will not delete characters from the JSON being parsed as this is a [requirement specified by the Unicode Standard][Unicode_UTR36_Deleting]. Additional information can be found in the [Unicode Security FAQ][Unicode_Security_FAQ] and [Unicode Technical Report #36 - Unicode Security Consideration][Unicode_UTR36], in particular the section on [non-visual security][Unicode_UTR36_NonVisualSecurity]. 77 | 78 | * The [JSON specification][RFC 4627] does not specify the details or requirements for JSON String values, other than such strings must consist of Unicode code points, nor does it specify how errors should be handled. While JSONKit makes an effort (subject to the reasonable caveats above regarding Unicode) to preserve the parsed JSON String exactly, it can not guarantee that [`NSString`][NSString] will preserve the exact Unicode semantics of the original JSON String. 79 | 80 | JSONKit does not perform any form of Unicode Normalization on the parsed JSON Strings, but can not make any guarantees that the [`NSString`][NSString] class will not perform Unicode Normalization on the parsed JSON String used to instantiate the [`NSString`][NSString] object. The [`NSString`][NSString] class may place additional restrictions or otherwise transform the JSON String in such a way so that the JSON String is not bijective with the instantiated [`NSString`][NSString] object. In other words, JSONKit can not guarantee that when you round trip a JSON String to a [`NSString`][NSString] and then back to a JSON String that the two JSON Strings will be exactly the same, even though in practice they are. For clarity, "exactly" in this case means bit for bit identical. JSONKit can not even guarantee that the two JSON Strings will be [Unicode equivalent][Unicode_equivalence], even though in practice they will be and would be the most likely cause for the two round tripped JSON Strings to no longer be bit for bit identical. 81 | 82 | * JSONKit maps `true` and `false` to the [`CFBoolean`][CFBoolean] values [`kCFBooleanTrue`][kCFBooleanTrue] and [`kCFBooleanFalse`][kCFBooleanFalse], respectively. Conceptually, [`CFBoolean`][CFBoolean] values can be thought of, and treated as, [`NSNumber`][NSNumber] class objects. The benefit to using [`CFBoolean`][CFBoolean] is that `true` and `false` JSON values can be round trip deserialized and serialized without conversion or promotion to a [`NSNumber`][NSNumber] with a value of `0` or `1`. 83 | 84 | * The [JSON specification][RFC 4627] does not specify the details or requirements for JSON Number values, nor does it specify how errors due to conversion should be handled. In general, JSONKit will not accept JSON that contains JSON Number values that it can not convert with out error or loss of precision. 85 | 86 | For non-floating-point numbers (i.e., JSON Number values that do not include a `.` or `e|E`), JSONKit uses a 64-bit C primitive type internally, regardless of whether the target architecture is 32-bit or 64-bit. For unsigned values (i.e., those that do not begin with a `-`), this allows for values up to 264-1 and up to -263 for negative values. As a special case, the JSON Number `-0` is treated as a floating-point number since the underlying floating-point primitive type is capable of representing a negative zero, whereas the underlying twos-complement non-floating-point primitive type can not. JSON that contains Number values that exceed these limits will fail to parse and optionally return a [`NSError`][NSError] object. The functions [`strtoll()`][strtoll] and [`strtoull()`][strtoull] are used to perform the conversions. 87 | 88 | The C `double` primitive type, or [IEEE 754 Double 64-bit floating-point][Double Precision], is used to represent floating-point JSON Number values. JSON that contains floating-point Number values that can not be represented as a `double` (i.e., due to over or underflow) will fail to parse and optionally return a [`NSError`][NSError] object. The function [`strtod()`][strtod] is used to perform the conversion. Note that the JSON standard does not allow for infinities or `NaN` (Not a Number). The conversion and manipulation of [floating-point values is non-trivial](http://www.validlab.com/goldberg/paper.pdf). Unfortunately, [RFC 4627][] is silent on how such details should be handled. You should not depend on or expect that when a floating-point value is round tripped that it will have the same textual representation or even compare equal. This is true even when JSONKit is used as both the parser and creator of the JSON, let alone when transferring JSON between different systems and implementations. 89 | 90 | * For JSON Objects (or [`NSDictionary`][NSDictionary] in JSONKit nomenclature), [RFC 4627][] says `The names within an object SHOULD be unique` (note: `name` is a `key` in JSONKit nomenclature). At this time the JSONKit behavior is `undefined` for JSON that contains names within an object that are not unique. However, JSONKit currently tries to follow a "the last key / value pair parsed is the one chosen" policy. This behavior is not finalized and should not be depended on. 91 | 92 | The previously covered limitations regarding JSON Strings have important consequences for JSON Objects since JSON Strings are used as the `key`. The [JSON specification][RFC 4627] does not specify the details or requirements for JSON Strings used as `keys` in JSON Objects, specifically what it means for two `keys` to compare equal. Unfortunately, because [RFC 4627][] states `JSON text SHALL be encoded in Unicode.`, this means that one must use the [Unicode Standard][] to interpret the JSON, and the [Unicode Standard][] allows for strings that are encoded with different Unicode Code Points to "compare equal". JSONKit uses [`NSString`][NSString] exclusively to manage the parsed JSON Strings. Because [`NSString`][NSString] uses [Unicode][Unicode Standard] as its basis, there exists the possibility that [`NSString`][NSString] may subtly and silently convert the Unicode Code Points contained in the original JSON String in to a [Unicode equivalent][Unicode_equivalence] string. Due to this, the JSONKit behavior for JSON Strings used as `keys` in JSON Objects that may be [Unicode equivalent][Unicode_equivalence] but not binary equivalent is `undefined`. 93 | 94 | **See also:**
95 |     [W3C - Requirements for String Identity Matching and String Indexing](http://www.w3.org/TR/charreq/#sec2) 96 | 97 | ### Objective-C To JSON Primitive Mapping Details 98 | 99 | * When serializing, the top level container, and all of its children, are required to be *strictly* [invariant][wiki_invariant] during enumeration. This property is used to make certain optimizations, such as if a particular object has already been serialized, the result of the previous serialized `UTF8` string can be reused (i.e., the `UTF8` string of the previous serialization can simply be copied instead of performing all the serialization work again). While this is probably only of interest to those who are doing extraordinarily unusual things with the run-time or custom classes inheriting from the classes that JSONKit will serialize (i.e, a custom object whose value mutates each time it receives a message requesting its value for serialization), it also covers the case where any of the objects to be serialized are mutated during enumeration (i.e., mutated by another thread). The number of times JSONKit will request an objects value is non-deterministic, from a minimum of once up to the number of times it appears in the serialized JSON– therefore an object MUST NOT depend on receiving a message requesting its value each time it appears in the serialized output. The behavior is `undefined` if these requirements are violated. 100 | 101 | * The objects to be serialized MUST be acyclic. If the objects to be serialized contain circular references the behavior is `undefined`. For example, 102 | 103 | ```objective-c 104 | [arrayOne addObject:arrayTwo]; 105 | [arrayTwo addObject:arrayOne]; 106 | id json = [arrayOne JSONString]; 107 | ``` 108 | 109 | … will result in `undefined` behavior. 110 | 111 | * The contents of [`NSString`][NSString] objects are encoded as `UTF8` and added to the serialized JSON. JSONKit assumes that [`NSString`][NSString] produces well-formed `UTF8` Unicode and does no additional validation of the conversion. When `JKSerializeOptionEscapeUnicode` is enabled, JSONKit will encode Unicode code points that can be encoded as a single `UTF16` code unit as \uXXXX, and will encode Unicode code points that require `UTF16` surrogate pairs as \uhigh\ulow. While JSONKit makes every effort to serialize the contents of a [`NSString`][NSString] object exactly, modulo any [RFC 4627][] requirements, the [`NSString`][NSString] class uses the [Unicode Standard][] as its basis for representing strings. You should be aware that the [Unicode Standard][] defines [string equivalence][Unicode_equivalence] in a such a way that two strings that compare equal are not required to be bit for bit identical. Therefore there exists the possibility that [`NSString`][NSString] may mutate a string in such a way that it is [Unicode equivalent][Unicode_equivalence], but not bit for bit identical with the original string. 112 | 113 | * The [`NSDictionary`][NSDictionary] class allows for any object, which can be of any class, to be used as a `key`. JSON, however, only permits Strings to be used as `keys`. Therefore JSONKit will fail with an error if it encounters a [`NSDictionary`][NSDictionary] that contains keys that are not [`NSString`][NSString] objects during serialization. More specifically, the keys must return `YES` when sent [`-isKindOfClass:[NSString class]`][-isKindOfClass:]. 114 | 115 | * JSONKit will fail with an error if it encounters an object that is not a [`NSNull`][NSNull], [`NSNumber`][NSNumber], [`NSString`][NSString], [`NSArray`][NSArray], or [`NSDictionary`][NSDictionary] class object during serialization. More specifically, JSONKit will fail with an error if it encounters an object where [`-isKindOfClass:`][-isKindOfClass:] returns `NO` for all of the previously mentioned classes. 116 | 117 | * JSON does not allow for Numbers that are ±Infinity or ±NaN. Therefore JSONKit will fail with an error if it encounters a [`NSNumber`][NSNumber] that contains such a value during serialization. 118 | 119 | * Objects created with [`[NSNumber numberWithBool:YES]`][NSNumber_numberWithBool] and [`[NSNumber numberWithBool:NO]`][NSNumber_numberWithBool] will be mapped to the JSON values of `true` and `false`, respectively. More specifically, an object must have pointer equality with [`kCFBooleanTrue`][kCFBooleanTrue] or [`kCFBooleanFalse`][kCFBooleanFalse] (i.e., `if((id)object == (id)kCFBooleanTrue)`) in order to be mapped to the JSON values `true` and `false`. 120 | 121 | * [`NSNumber`][NSNumber] objects that are not booleans (as defined above) are sent [`-objCType`][-objCType] to determine what type of C primitive type they represent. Those that respond with a type from the set `cislq` are treated as `long long`, those that respond with a type from the set `CISLQB` are treated as `unsigned long long`, and those that respond with a type from the set `fd` are treated as `double`. [`NSNumber`][NSNumber] objects that respond with a type not in the set of types mentioned will cause JSONKit to fail with an error. 122 | 123 | More specifically, [`CFNumberGetValue(object, kCFNumberLongLongType, &longLong)`][CFNumberGetValue] is used to retrieve the value of both the signed and unsigned integer values, and the type reported by [`-objCType`][-objCType] is used to determine whether the result is signed or unsigned. For floating-point values, [`CFNumberGetValue`][CFNumberGetValue] is used to retrieve the value using [`kCFNumberDoubleType`][kCFNumberDoubleType] for the type argument. 124 | 125 | Floating-point numbers are converted to their decimal representation using the [`printf`][printf] format conversion specifier `%.17g`. Theoretically this allows up to a `float`, or [IEEE 754 Single 32-bit floating-point][Single Precision], worth of precision to be represented. This means that for practical purposes, `double` values are converted to `float` values with the associated loss of precision. The [RFC 4627][] standard is silent on how floating-point numbers should be dealt with and the author has found that real world JSON implementations vary wildly in how they handle this issue. Furthermore, the `%g` format conversion specifier may convert floating-point values that can be exactly represented as an integer to a textual representation that does not include a `.` or `e`– essentially silently promoting a floating-point value to an integer value (i.e, `5.0` becomes `5`). Because of these and many other issues surrounding the conversion and manipulation of floating-point values, you should not expect or depend on floating point values to maintain their full precision, or when round tripped, to compare equal. 126 | 127 | 128 | ### Reporting Bugs 129 | 130 | Please use the [github.com JSONKit Issue Tracker](https://github.com/johnezang/JSONKit/issues) to report bugs. 131 | 132 | The author requests that you do not file a bug report with JSONKit regarding problems reported by the `clang` static analyzer unless you first manually verify that it is an actual, bona-fide problem with JSONKit and, if appropriate, is not "legal" C code as defined by the C99 language specification. If the `clang` static analyzer is reporting a problem with JSONKit that is not an actual, bona-fide problem and is perfectly legal code as defined by the C99 language specification, then the appropriate place to file a bug report or complaint is with the developers of the `clang` static analyzer. 133 | 134 | ### Important Details 135 | 136 | * JSONKit is not designed to be used with the Mac OS X Garbage Collection. The behavior of JSONKit when compiled with `-fobjc-gc` is `undefined`. It is extremely unlikely that Mac OS X Garbage Collection will ever be supported. 137 | 138 | * JSONKit is not designed to be used with [Objective-C Automatic Reference Counting (ARC)][ARC]. The behavior of JSONKit when compiled with `-fobjc-arc` is `undefined`. The behavior of JSONKit compiled without [ARC][] mixed with code that has been compiled with [ARC][] is normatively `undefined` since at this time no analysis has been done to understand if this configuration is safe to use. At this time, there are no plans to support [ARC][] in JSONKit. Although tenative, it is extremely unlikely that [ARC][] will ever be supported, for many of the same reasons that Mac OS X Garbage Collection is not supported. 139 | 140 | * The JSON to be parsed by JSONKit MUST be encoded as Unicode. In the unlikely event you end up with JSON that is not encoded as Unicode, you must first convert the JSON to Unicode, preferably as `UTF8`. One way to accomplish this is with the [`NSString`][NSString] methods [`-initWithBytes:length:encoding:`][NSString_initWithBytes] and [`-initWithData:encoding:`][NSString_initWithData]. 141 | 142 | * Internally, the low level parsing engine uses `UTF8` exclusively. The `JSONDecoder` method `-objectWithData:` takes a [`NSData`][NSData] object as its argument and it is assumed that the raw bytes contained in the [`NSData`][NSData] is `UTF8` encoded, otherwise the behavior is `undefined`. 143 | 144 | * It is not safe to use the same instantiated `JSONDecoder` object from multiple threads at the same time. If you wish to share a `JSONDecoder` between threads, you are responsible for adding mutex barriers to ensure that only one thread is decoding JSON using the shared `JSONDecoder` object at a time. 145 | 146 | ### Tips for speed 147 | 148 | * Enable the `NS_BLOCK_ASSERTIONS` pre-processor flag. JSONKit makes heavy use of [`NSCParameterAssert()`][NSCParameterAssert] internally to ensure that various arguments, variables, and other state contains only legal and expected values. If an assertion check fails it causes a run time exception that will normally cause a program to terminate. These checks and assertions come with a price: they take time to execute and do not contribute to the work being performed. It is perfectly safe to enable `NS_BLOCK_ASSERTIONS` as JSONKit always performs checks that are required for correct operation. The checks performed with [`NSCParameterAssert()`][NSCParameterAssert] are completely optional and are meant to be used in "debug" builds where extra integrity checks are usually desired. While your mileage may vary, the author has found that adding `-DNS_BLOCK_ASSERTIONS` to an `-O2` optimization setting can generally result in an approximate 7-12% increase in performance. 149 | 150 | * Since the very low level parsing engine works exclusively with `UTF8` byte streams, anything that is not already encoded as `UTF8` must first be converted to `UTF8`. While JSONKit provides additions to the [`NSString`][NSString] class which allows you to conveniently convert JSON contained in a [`NSString`][NSString], this convenience does come with a price. JSONKit must allocate an autoreleased [`NSMutableData`][NSMutableData] large enough to hold the strings `UTF8` conversion and then convert the string to `UTF8` before it can begin parsing. This takes both memory and time. Once the parsing has finished, JSONKit sets the autoreleased [`NSMutableData`][NSMutableData] length to `0`, which allows the [`NSMutableData`][NSMutableData] to release the memory. This helps to minimize the amount of memory that is in use but unavailable until the autorelease pool pops. Therefore, if speed and memory usage are a priority, you should avoid using the [`NSString`][NSString] convenience methods if possible. 151 | 152 | * If you are receiving JSON data from a web server, and you are able to determine that the raw bytes returned by the web server is JSON encoded as `UTF8`, you should use the `JSONDecoder` method `-objectWithUTF8String:length:` which immediately begins parsing the pointers bytes. In practice, every JSONKit method that converts JSON to an Objective-C object eventually calls this method to perform the conversion. 153 | 154 | * If you are using one of the various ways provided by the `NSURL` family of classes to receive JSON results from a web server, which typically return the results in the form of a [`NSData`][NSData] object, and you are able to determine that the raw bytes contained in the [`NSData`][NSData] are encoded as `UTF8`, then you should use either the `JSONDecoder` method `objectWithData:` or the [`NSData`][NSData] method `-objectFromJSONData`. If are going to be converting a lot of JSON, the better choice is to instantiate a `JSONDecoder` object once and use the same instantiated object to perform all your conversions. This has two benefits: 155 | 1. The [`NSData`][NSData] method `-objectFromJSONData` creates an autoreleased `JSONDecoder` object to perform the one time conversion. By instantiating a `JSONDecoder` object once and using the `objectWithData:` method repeatedly, you can avoid this overhead. 156 | 2. The instantiated object cache from the previous JSON conversion is reused. This can result in both better performance and a reduction in memory usage if the JSON your are converting is very similar. A typical example might be if you are converting JSON at periodic intervals that consists of real time status updates. 157 | 158 | * On average, the JSONData… methods are nearly four times faster than the JSONString… methods when serializing a [`NSDictionary`][NSDictionary] or [`NSArray`][NSArray] to JSON. The difference in speed is due entirely to the instantiation overhead of [`NSString`][NSString]. 159 | 160 | * If at all possible, use [`NSData`][NSData] instead of [`NSString`][NSString] methods when processing JSON. This avoids the sometimes significant conversion overhead that [`NSString`][NSString] performs in order to provide an object oriented interface for its contents. For many uses, using [`NSString`][NSString] is not needed and results in wasted effort– for example, using JSONKit to serialize a [`NSDictionary`][NSDictionary] or [`NSArray`][NSArray] to a [`NSString`][NSString]. This [`NSString`][NSString] is then passed to a method that sends the JSON to a web server, and this invariably requires converting the [`NSString`][NSString] to [`NSData`][NSData] before it can be sent. In this case, serializing the collection object directly to [`NSData`][NSData] would avoid the unnecessary conversions to and from a [`NSString`][NSString] object. 161 | 162 | ### Parsing Interface 163 | 164 | #### JSONDecoder Interface 165 | 166 | The objectWith… methods return immutable collection objects and their respective mutableObjectWith… methods return mutable collection objects. 167 | 168 | **Note:** The bytes contained in a [`NSData`][NSData] object ***MUST*** be `UTF8` encoded. 169 | 170 | **Important:** Methods will raise [`NSInvalidArgumentException`][NSInvalidArgumentException] if `parseOptionFlags` is not valid. 171 | **Important:** `objectWithUTF8String:` and `mutableObjectWithUTF8String:` will raise [`NSInvalidArgumentException`][NSInvalidArgumentException] if `string` is `NULL`. 172 | **Important:** `objectWithData:` and `mutableObjectWithData:` will raise [`NSInvalidArgumentException`][NSInvalidArgumentException] if `jsonData` is `NULL`. 173 | 174 | ```objective-c 175 | + (id)decoder; 176 | + (id)decoderWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 177 | - (id)initWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 178 | 179 | - (void)clearCache; 180 | 181 | - (id)objectWithUTF8String:(const unsigned char *)string length:(size_t)length; 182 | - (id)objectWithUTF8String:(const unsigned char *)string length:(size_t)length error:(NSError **)error; 183 | - (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(size_t)length; 184 | - (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(size_t)length error:(NSError **)error; 185 | 186 | - (id)objectWithData:(NSData *)jsonData; 187 | - (id)objectWithData:(NSData *)jsonData error:(NSError **)error; 188 | - (id)mutableObjectWithData:(NSData *)jsonData; 189 | - (id)mutableObjectWithData:(NSData *)jsonData error:(NSError **)error; 190 | ``` 191 | 192 | #### NSString Interface 193 | 194 | ```objective-c 195 | - (id)objectFromJSONString; 196 | - (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 197 | - (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 198 | - (id)mutableObjectFromJSONString; 199 | - (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 200 | - (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 201 | ``` 202 | 203 | #### NSData Interface 204 | 205 | ```objective-c 206 | - (id)objectFromJSONData; 207 | - (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 208 | - (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 209 | - (id)mutableObjectFromJSONData; 210 | - (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags; 211 | - (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error; 212 | ``` 213 | 214 | #### JKParseOptionFlags 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 |
Parsing OptionDescription
JKParseOptionNoneThis is the default if no other other parse option flags are specified, and the option used when a convenience method does not provide an argument for explicitly specifying the parse options to use. Synonymous with JKParseOptionStrict.
JKParseOptionStrictThe JSON will be parsed in strict accordance with the RFC 4627 specification.
JKParseOptionCommentsAllow C style // and /* … */ comments in JSON. This is a fairly common extension to JSON, but JSON that contains C style comments is not strictly conforming JSON.
JKParseOptionUnicodeNewlinesAllow Unicode recommended (?:\r\n|[\n\v\f\r\x85\p{Zl}\p{Zp}]) newlines in JSON. The JSON specification only allows the newline characters \r and \n, but this option allows JSON that contains the Unicode recommended newline characters to be parsed. JSON that contains these additional newline characters is not strictly conforming JSON.
JKParseOptionLooseUnicodeNormally the decoder will stop with an error at any malformed Unicode. This option allows JSON with malformed Unicode to be parsed without reporting an error. Any malformed Unicode is replaced with \uFFFD, or REPLACEMENT CHARACTER, as specified in The Unicode 6.0 standard, Chapter 3, section 3.9 Unicode Encoding Forms.
JKParseOptionPermitTextAfterValidJSONNormally, non-white-space that follows the JSON is interpreted as a parsing failure. This option allows for any trailing non-white-space to be ignored and not cause a parsing error.
225 | 226 | ### Serializing Interface 227 | 228 | The serializing interface includes [`NSString`][NSString] convenience methods for those that need to serialize a single [`NSString`][NSString]. For those that need this functionality, the [`NSString`][NSString] additions are much more convenient than having to wrap a single [`NSString`][NSString] in a [`NSArray`][NSArray], which then requires stripping the unneeded `[`…`]` characters from the serialized JSON result. When serializing a single [`NSString`][NSString], you can control whether or not the serialized JSON result is surrounded by quotation marks using the `includeQuotes:` argument: 229 | 230 | Example | Result | Argument 231 | --------------|-------------------|-------------------- 232 | `a "test"...` | `"a \"test\"..."` | `includeQuotes:YES` 233 | `a "test"...` | `a \"test\"...` | `includeQuotes:NO` 234 | 235 | **Note:** The [`NSString`][NSString] methods that do not include a `includeQuotes:` argument behave as if invoked with `includeQuotes:YES`. 236 | **Note:** The bytes contained in the returned [`NSData`][NSData] object are `UTF8` encoded. 237 | 238 | #### NSArray and NSDictionary Interface 239 | 240 | ```objective-c 241 | - (NSData *)JSONData; 242 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 243 | - (NSString *)JSONString; 244 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error; 245 | ``` 246 | 247 | 248 | #### NSString Interface 249 | 250 | ```objective-c 251 | - (NSData *)JSONData; 252 | - (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error; 253 | - (NSString *)JSONString; 254 | - (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error; 255 | ``` 256 | 257 | #### JKSerializeOptionFlags 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 |
Serializing OptionDescription
JKSerializeOptionNoneThis is the default if no other other serialize option flags are specified, and the option used when a convenience method does not provide an argument for explicitly specifying the serialize options to use.
JKSerializeOptionPrettyNormally the serialized JSON does not include any unnecessary white-space. While this form is the most compact, the lack of any white-space means that it's something only another JSON parser could love. Enabling this option causes JSONKit to add additional white-space that makes it easier for people to read. Other than the extra white-space, the serialized JSON is identical to the JSON that would have been produced had this option not been enabled.
JKSerializeOptionEscapeUnicodeWhen JSONKit encounters Unicode characters in NSString objects, the default behavior is to encode those Unicode characters as UTF8. This option causes JSONKit to encode those characters as \uXXXX. For example,
["w∈L⟺y(∣y∣≤∣w∣)"]
becomes:
["w\u2208L\u27fa\u2203y(\u2223y\u2223\u2264\u2223w\u2223)"]
JKSerializeOptionEscapeForwardSlashesAccording to the JSON specification, the / (U+002F) character may be backslash escaped (i.e., \/), but it is not required. The default behavior of JSONKit is to not backslash escape the / character. Unfortunately, it was found some real world implementations of the ASP.NET Date Format require the date to be strictly encoded as \/Date(...)\/, and the only way to achieve this is through the use of JKSerializeOptionEscapeForwardSlashes. See github issue #21 for more information.
266 | 267 | [JSON]: http://www.json.org/ 268 | [RFC 4627]: http://tools.ietf.org/html/rfc4627 269 | [RFC 2119]: http://tools.ietf.org/html/rfc2119 270 | [Single Precision]: http://en.wikipedia.org/wiki/Single_precision_floating-point_format 271 | [Double Precision]: http://en.wikipedia.org/wiki/Double_precision_floating-point_format 272 | [wiki_invariant]: http://en.wikipedia.org/wiki/Invariant_(computer_science) 273 | [ARC]: http://clang.llvm.org/docs/AutomaticReferenceCounting.html 274 | [CFBoolean]: http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFBooleanRef/index.html 275 | [kCFBooleanTrue]: http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFBooleanRef/Reference/reference.html#//apple_ref/doc/c_ref/kCFBooleanTrue 276 | [kCFBooleanFalse]: http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFBooleanRef/Reference/reference.html#//apple_ref/doc/c_ref/kCFBooleanFalse 277 | [kCFNumberDoubleType]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFNumberRef/Reference/reference.html#//apple_ref/doc/c_ref/kCFNumberDoubleType 278 | [CFNumberGetValue]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFNumberRef/Reference/reference.html#//apple_ref/c/func/CFNumberGetValue 279 | [Unicode Standard]: http://www.unicode.org/versions/Unicode6.0.0/ 280 | [Unicode Standard - Conformance]: http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf 281 | [Unicode_equivalence]: http://en.wikipedia.org/wiki/Unicode_equivalence 282 | [UnicodeNewline]: http://en.wikipedia.org/wiki/Newline#Unicode 283 | [Unicode_UTR36]: http://www.unicode.org/reports/tr36/ 284 | [Unicode_UTR36_NonVisualSecurity]: http://www.unicode.org/reports/tr36/#Canonical_Represenation 285 | [Unicode_UTR36_Deleting]: http://www.unicode.org/reports/tr36/#Deletion_of_Noncharacters 286 | [Unicode_Security_FAQ]: http://www.unicode.org/faq/security.html 287 | [NSNull]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNull_Class/index.html 288 | [NSNumber]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html 289 | [NSNumber_numberWithBool]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html#//apple_ref/occ/clm/NSNumber/numberWithBool: 290 | [NSString]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html 291 | [NSString_initWithBytes]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/initWithBytes:length:encoding: 292 | [NSString_initWithData]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/initWithData:encoding: 293 | [NSString_UTF8String]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/UTF8String 294 | [NSArray]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html 295 | [NSDictionary]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/index.html 296 | [NSError]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/index.html 297 | [NSData]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/index.html 298 | [NSMutableData]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/index.html 299 | [NSInvalidArgumentException]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSInvalidArgumentException 300 | [CFString]: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html 301 | [NSCParameterAssert]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/macro/NSCParameterAssert 302 | [-mutableCopy]: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSObject/mutableCopy 303 | [-isKindOfClass:]: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html%23//apple_ref/occ/intfm/NSObject/isKindOfClass: 304 | [-objCType]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html#//apple_ref/occ/instm/NSNumber/objCType 305 | [strtoll]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strtoll.3.html 306 | [strtod]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strtod.3.html 307 | [strtoull]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strtoull.3.html 308 | [getrusage]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/getrusage.2.html 309 | [printf]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/printf.3.html 310 | [NSJSONSerialization]: http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html 311 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Models/RPCError.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCError.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | // Reserved rpc errors 13 | typedef enum { 14 | RPCParseError = -32700, 15 | RPCInvalidRequest = -32600, 16 | RPCMethodNotFound = -32601, 17 | RPCInvalidParams = -32602, 18 | RPCInternalError = -32603, 19 | RPCServerError = 32000, 20 | RPCNetworkError = 32001 21 | } RPCErrorCode; 22 | 23 | /** 24 | * RPCError. 25 | * 26 | * Simple object containing information about errors. Erros can be generated serverside or internally within this client. 27 | * See RPCErrorCode above for the most common errors. 28 | */ 29 | @interface RPCError : NSObject 30 | 31 | #pragma mark - Properties - 32 | 33 | /** 34 | * RPC Error code. Error code that you can match against the RPCErrorCode enum above. 35 | * 36 | * Server can generate other errors aswell, for a description of server errors you need to contact server 37 | * administrator ;-) 38 | * 39 | * @param RPCErrorCode 40 | */ 41 | @property (nonatomic, readonly) RPCErrorCode code; 42 | 43 | /** 44 | * RPC Error message 45 | * 46 | * A more detailed message describing the error. 47 | * 48 | * @param NSString 49 | */ 50 | @property (nonatomic, readonly, retain) NSString *message; 51 | 52 | /** 53 | * Some random data 54 | * 55 | * If the server supports sending debug data when server errors accours, it will be stored here 56 | * 57 | * @param id 58 | */ 59 | @property (nonatomic, readonly, retain) id data; 60 | 61 | #pragma mark - Methods 62 | 63 | // These methods is self explaining.. right? 64 | - (id) initWithCode:(RPCErrorCode) code; 65 | - (id) initWithCode:(RPCErrorCode) code message:(NSString*) message data:(id)data; 66 | + (id) errorWithCode:(RPCErrorCode) code; 67 | + (id) errorWithDictionary:(NSDictionary*) error; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Models/RPCError.m: -------------------------------------------------------------------------------- 1 | // 2 | // RPCError.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "RPCError.h" 10 | 11 | @implementation RPCError 12 | @synthesize code = _code; 13 | @synthesize message = _message; 14 | @synthesize data = _data; 15 | 16 | - (id) initWithCode:(RPCErrorCode) code message:(NSString*) message data:(id)data 17 | { 18 | self = [super init]; 19 | 20 | if(self) 21 | { 22 | _code = code; 23 | _message = [message retain]; 24 | _data = [data retain]; 25 | } 26 | 27 | return self; 28 | } 29 | 30 | - (id) initWithCode:(RPCErrorCode) code 31 | { 32 | NSString *message; 33 | 34 | switch (code) { 35 | case RPCParseError: 36 | message = @"Parse error"; 37 | break; 38 | 39 | case RPCInternalError: 40 | message = @"Internal error"; 41 | break; 42 | 43 | case RPCInvalidParams: 44 | message = @"Invalid params"; 45 | break; 46 | 47 | case RPCInvalidRequest: 48 | message = @"Invalid Request"; 49 | break; 50 | 51 | case RPCMethodNotFound: 52 | message = @"Method not found"; 53 | break; 54 | 55 | case RPCNetworkError: 56 | message = @"Network error"; 57 | break; 58 | 59 | case RPCServerError: 60 | default: 61 | message = @"Server error"; 62 | break; 63 | } 64 | 65 | return [self initWithCode:code message:message data:nil]; 66 | } 67 | 68 | + (id) errorWithCode:(RPCErrorCode) code 69 | { 70 | return [[[RPCError alloc] initWithCode:code] autorelease]; 71 | } 72 | 73 | + (id) errorWithDictionary:(NSDictionary*) error 74 | { 75 | return [[[RPCError alloc] initWithCode:[[error objectForKey:@"code"] intValue] 76 | message:[error objectForKey:@"message"] 77 | data:[error objectForKey:@"data"]] autorelease]; 78 | } 79 | 80 | - (void) dealloc 81 | { 82 | [_message release]; 83 | [_data release]; 84 | 85 | [super dealloc]; 86 | } 87 | 88 | - (NSString*) description 89 | { 90 | if(self.data != nil) 91 | return [NSString stringWithFormat:@"RPCError: %@ (%i): %@.", self.message, self.code, self.data]; 92 | else 93 | return [NSString stringWithFormat:@"RPCError: %@ (%i).", self.message, self.code]; 94 | } 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Models/RPCRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCRequest.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class RPCResponse; 12 | 13 | // Callback type 14 | typedef void (^RPCRequestCallback)(RPCResponse *response); 15 | 16 | /** 17 | * RPC Request object. 18 | * 19 | * Always used to invoke a request to an endpoint. 20 | */ 21 | @interface RPCRequest : NSObject 22 | 23 | #pragma mark - Properties - 24 | 25 | /** 26 | * The used RPC Version. 27 | * This client only supports version 2.0 at the moment. 28 | * 29 | * @param NSString 30 | */ 31 | @property (nonatomic, retain) NSString *version; 32 | 33 | /** 34 | * The id that was used in the request. If id is nil the request is treated like an notification. 35 | * 36 | * @param NSString 37 | */ 38 | @property (nonatomic, retain) NSString *id; 39 | 40 | /** 41 | * Method to call at the RPC Server. 42 | * 43 | * @param NSString 44 | */ 45 | @property (nonatomic, retain) NSString *method; 46 | 47 | /** 48 | * Request params. Either named, un-named or nil 49 | * 50 | * @param id 51 | */ 52 | @property (nonatomic, retain) id params; 53 | 54 | /** 55 | * Callback to call whenever request is fininshed 56 | * 57 | * @param RPCRequestCallback 58 | */ 59 | @property (nonatomic, copy) RPCRequestCallback callback; 60 | 61 | #pragma mark - methods 62 | 63 | /** 64 | * Serialized requests object for json encodig 65 | * 66 | */ 67 | - (NSMutableDictionary*) serialize; 68 | 69 | /** 70 | * Helper method to get an autoreleased request object 71 | * 72 | * @param NSString method The method that this request if for 73 | * @return RPCRequest (autoreleased) 74 | */ 75 | + (id) requestWithMethod:(NSString*) method; 76 | 77 | /** 78 | * Helper method to get an autoreleased request object 79 | * 80 | * @param NSString method The method that this request if for 81 | * @param id params Some parameters to send along with the request, either named, un-named or nil 82 | * @return RPCRequest (autoreleased) 83 | */ 84 | + (id) requestWithMethod:(NSString*) method params:(id) params; 85 | 86 | /** 87 | * Helper method to get an autoreleased request object 88 | * 89 | * @param NSString method The method that this request if for 90 | * @param id params Some parameters to send along with the request, either named, un-named or nil 91 | * @param RPCRequestCallback the callback to call once the request is finished 92 | * @return RPCRequest (autoreleased) 93 | */ 94 | + (id) requestWithMethod:(NSString*) method params:(id) params callback:(RPCRequestCallback)callback; 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Models/RPCRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // RPCRequest.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "RPCRequest.h" 10 | 11 | @implementation RPCRequest 12 | @synthesize version = _version; 13 | @synthesize method = _method; 14 | @synthesize params = _params; 15 | @synthesize callback = _callback; 16 | @synthesize id = _id; 17 | 18 | - (id) init 19 | { 20 | self = [super init]; 21 | 22 | if(self) 23 | { 24 | self.version = @"2.0"; 25 | self.method = nil; 26 | self.params = nil; 27 | self.callback = nil; 28 | 29 | self.id = [[NSNumber numberWithInt:arc4random()] stringValue]; 30 | } 31 | 32 | return self; 33 | } 34 | 35 | + (id) requestWithMethod:(NSString*) method 36 | { 37 | RPCRequest *request = [[RPCRequest alloc] init]; 38 | request.method = method; 39 | 40 | return [request autorelease]; 41 | } 42 | 43 | + (id) requestWithMethod:(NSString*) method params:(id) params 44 | { 45 | RPCRequest *request = [[self requestWithMethod:method] retain]; 46 | request.params = params; 47 | 48 | return [request autorelease]; 49 | } 50 | 51 | + (id) requestWithMethod:(NSString*) method params:(id) params callback:(RPCRequestCallback)callback 52 | { 53 | RPCRequest *request = [[self requestWithMethod:method params:params] retain]; 54 | request.callback = callback; 55 | 56 | return [request autorelease]; 57 | } 58 | 59 | - (NSMutableDictionary*) serialize 60 | { 61 | NSMutableDictionary *payload = [[NSMutableDictionary alloc] init]; 62 | 63 | if(self.version) 64 | [payload setObject:self.version forKey:@"jsonrpc"]; 65 | 66 | if(self.method) 67 | [payload setObject:self.method forKey:@"method"]; 68 | 69 | if(self.params) 70 | [payload setObject:self.params forKey:@"params"]; 71 | 72 | if(self.id) 73 | [payload setObject:self.id forKey:@"id"]; 74 | 75 | return [payload autorelease]; 76 | } 77 | 78 | - (void) dealloc 79 | { 80 | [_version release]; 81 | [_method release]; 82 | [_params release]; 83 | [_id release]; 84 | [_callback release]; 85 | 86 | [super dealloc]; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Models/RPCResponse.h: -------------------------------------------------------------------------------- 1 | // 2 | // RPCResponse.h 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RPCError.h" 11 | 12 | /** 13 | * RPC Resposne object 14 | * 15 | * This object is created when the server responds. 16 | */ 17 | @interface RPCResponse : NSObject 18 | 19 | /** 20 | * The used RPC Version. 21 | * 22 | * @param NSString 23 | */ 24 | @property (nonatomic, retain) NSString *version; 25 | 26 | /** 27 | * The id that was used in the request. 28 | * 29 | * @param NSString 30 | */ 31 | @property (nonatomic, retain) NSString *id; 32 | 33 | /** 34 | * RPC Error. If != nil it means there was an error 35 | * 36 | * @return RPCError 37 | */ 38 | @property (nonatomic, retain) RPCError *error; 39 | 40 | /** 41 | * An object represneting the result from the method on the server 42 | * 43 | * @param id 44 | */ 45 | @property (nonatomic, retain) id result; 46 | 47 | 48 | #pragma mark - Methods 49 | 50 | /** 51 | * Helper method to get an autoreleased RPCResponse object with an error set 52 | * 53 | * @param RPCError error The error for the response 54 | * @return RPCRequest 55 | */ 56 | + (id) responseWithError:(RPCError*)error; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /objc-JSONRpc/RPC Client/Models/RPCResponse.m: -------------------------------------------------------------------------------- 1 | // 2 | // RPCResponse.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import "RPCResponse.h" 10 | 11 | @implementation RPCResponse 12 | @synthesize version = _version; 13 | @synthesize error = _error; 14 | @synthesize result = _result; 15 | @synthesize id = _id; 16 | 17 | - (id) init 18 | { 19 | self = [super init]; 20 | 21 | if(self) 22 | { 23 | self.version = nil; 24 | self.error = nil; 25 | self.result = nil; 26 | self.id = nil; 27 | } 28 | 29 | return self; 30 | } 31 | 32 | + (id) responseWithError:(RPCError*)error 33 | { 34 | RPCResponse *response = [[RPCResponse alloc] init]; 35 | response.error = error; 36 | 37 | return [response autorelease]; 38 | } 39 | 40 | - (void) dealloc 41 | { 42 | [_version release]; 43 | [_error release]; 44 | [_result release]; 45 | [_id release]; 46 | [super dealloc]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /objc-JSONRpc/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /objc-JSONRpc/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // objc-JSONRpc 4 | // 5 | // Created by Rasmus Styrk on 8/28/12. 6 | // Copyright (c) 2012 Rasmus Styrk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /objc-JSONRpc/objc-JSONRpc-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | styrk-it.dk.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /objc-JSONRpc/objc-JSONRpc-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'objc-JSONRpc' target in the 'objc-JSONRpc' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iOS SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | --------------------------------------------------------------------------------