mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2026-04-24 00:00:04 +08:00
Added JSON support to GCDWebServerDataResponse
This commit is contained in:
@@ -211,6 +211,10 @@
|
||||
return ARC_AUTORELEASE([[self alloc] initWithHTMLTemplate:path variables:variables]);
|
||||
}
|
||||
|
||||
+ (GCDWebServerDataResponse*)responseWithJSONObject:(id)object {
|
||||
return ARC_AUTORELEASE([[self alloc] initWithJSONObject:object]);
|
||||
}
|
||||
|
||||
- (id)initWithText:(NSString*)text {
|
||||
NSData* data = [text dataUsingEncoding:NSUTF8StringEncoding];
|
||||
if (data == nil) {
|
||||
@@ -241,6 +245,15 @@
|
||||
return response;
|
||||
}
|
||||
|
||||
- (id)initWithJSONObject:(id)object {
|
||||
NSData* data = [NSJSONSerialization dataWithJSONObject:object options:0 error:NULL];
|
||||
if (data == nil) {
|
||||
ARC_RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
return [self initWithData:data contentType:@"application/json"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GCDWebServerFileResponse
|
||||
|
||||
Reference in New Issue
Block a user