mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-22 11:46:05 +08:00
Added JSON serialization class for easily coercing any NSObject into a JSON serialization for communication with servers expecting JSON input
This commit is contained in:
40
Code/RKJSONSerialization.m
Normal file
40
Code/RKJSONSerialization.m
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// RKJSONSerialization.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 7/8/10.
|
||||
// Copyright 2010 Two Toasters. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKJSONSerialization.h"
|
||||
#import "NSObject+SBJSON.h"
|
||||
|
||||
@implementation RKJSONSerialization
|
||||
|
||||
+ (id)JSONSerializationWithObject:(NSObject*)object {
|
||||
return [[[self alloc] initWithObject:object] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithObject:(NSObject*)object {
|
||||
if (self = [self init]) {
|
||||
_object = [object retain];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_object release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)ContentTypeHTTPHeader {
|
||||
return @"application/json";
|
||||
}
|
||||
|
||||
|
||||
- (NSData*)HTTPBody {
|
||||
return [[_object JSONRepresentation] dataUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user