Files
RestKit/Code/Network/RKJSONSerialization.m
Blake Watters c35d0bab1d Implemented substantial catalog example application covering advanced usage of RestKit:
* Cleaned up remaining warnings about if (self = [super init])
* RKParamsExample - Highlights multi-part uploads
* RKRequestQueueExample - Working with the request queue
* RKBackgroundRequestExample - Examples of using the background policies for backgrounding requests
* RKReachabilityExample - Shows how to work with the reachability observer
* RKRelationshipMappingExample - Shows how to map related objects from JSON into an object graph
* RKCoreDataExample - Shows the basics of using RestKit's Core Data examples

Also rearranged dispatch of RKRequest delegate method for didStartLoad: to ensure requeue callbacks get invoked in a timely manner. refs #62
2011-04-22 11:28:56 -04:00

55 lines
1.2 KiB
Objective-C

//
// RKJSONSerialization.m
// RestKit
//
// Created by Blake Watters on 7/8/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKJSONSerialization.h"
#import "NSObject+RKJSONSerialization.h"
#import "RKJSONParser.h"
@implementation RKJSONSerialization
+ (id)JSONSerializationWithObject:(NSObject*)object {
return [[[self alloc] initWithObject:object] autorelease];
}
- (id)initWithObject:(NSObject*)object {
self = [self init];
if (self) {
_object = [object retain];
}
return self;
}
- (void)dealloc {
[_object release];
[super dealloc];
}
- (NSString*)HTTPHeaderValueForContentType {
return @"application/json";
}
- (NSString*)JSONRepresentation {
return [[[[RKJSONParser alloc] init] autorelease] stringFromObject:_object];
}
- (NSData*)HTTPBody {
return [[self JSONRepresentation] dataUsingEncoding:NSUTF8StringEncoding];
}
- (BOOL)isEqual:(id)object {
if ([object isKindOfClass:[NSString class]]) {
return [[self JSONRepresentation] isEqualToString:object];
} else {
NSString* string = [[[[RKJSONParser alloc] init] autorelease] stringFromObject:object];
return [[self JSONRepresentation] isEqualToString:string];
}
}
@end