Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed several bugs and Objective-C no-nos (like using an NSError poin…

…ter to check validity). Also made the style consistent.
  • Loading branch information...
commit 78c6e11122ac2cc4e1bd4e3df7c922215d55e0e8 1 parent 70ff263
@alanzeino authored
Showing with 13 additions and 11 deletions.
  1. +13 −11 SBJSONCategories.m
View
24 SBJSONCategories.m
@@ -20,7 +20,7 @@
@implementation NSObject (SBJSONCategories)
--(NSString*) jsonWithOption:(int) option
+- (NSString *)jsonWithOption:(int)option
{
NSError *err = nil;
@@ -28,20 +28,22 @@ -(NSString*) jsonWithOption:(int) option
options:option
error:&err];
- if(err)
+ if (data == nil)
+ {
NSLog(@"%@", [err description]);
+ return nil;
+ }
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
}
-- (NSString *)prettyJSON {
-
+- (NSString *)prettyJSON
+{
return [self jsonWithOption:NSJSONWritingPrettyPrinted];
}
-- (NSString *)JSONRepresentation {
-
+- (NSString *)JSONRepresentation
+{
return [self jsonWithOption:0];
}
@@ -50,15 +52,15 @@ - (NSString *)JSONRepresentation {
@implementation NSString (SBJSONCategories)
-- (id)JSONValue {
-
+- (id)JSONValue
+{
NSError *err = nil;
NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
id jsonValue = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
error:&err];
- if(err)
+ if (jsonValue == nil)
NSLog(@"%@", [err description]);
return jsonValue;
@@ -74,7 +76,7 @@ - (id)JSONValue
options:0
error:&err];
- if(err)
+ if (jsonValue == nil)
NSLog(@"%@", [err description]);
return jsonValue;
Please sign in to comment.
Something went wrong with that request. Please try again.