-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONHelpers.m
40 lines (30 loc) · 929 Bytes
/
JSONHelpers.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// JSONHelpers.m
// PenguinSample
//
// Created on 11/5/14.
// Copyright (c) 2014 AT&T. All rights reserved.
//
#import "JSONHelpers.h"
@implementation JSONHelpers
+ (id)contentFromJsonResponse:(NSData *)jsonData
{
// convert JSON response to native objects
NSError *error;
NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (error || !responseJSON) {
return nil;
}
return responseJSON[@"content"];
}
+ (NSArray *)contentArrayFromJsonResponse:(NSData *)jsonData
{
id content = [self contentFromJsonResponse:jsonData];
return (content && [content isKindOfClass:[NSArray class]])?content:nil;
}
+ (NSDictionary *)contentDictionaryFromJsonResponse:(NSData *)jsonData
{
id content = [self contentFromJsonResponse:jsonData];
return (content && [content isKindOfClass:[NSDictionary class]])?content:nil;
}
@end