forked from haxpor/Potatso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSONUtils.m
45 lines (32 loc) · 1.04 KB
/
JSONUtils.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
41
42
43
44
45
//
// JSONUtils.m
// Potatso
//
// Created by LEI on 3/15/16.
// Copyright © 2016 TouchingApp. All rights reserved.
//
#import "JSONUtils.h"
@implementation NSString (JSON)
- (NSDictionary *)jsonDictionary {
return [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
}
- (NSArray *)jsonArray {
return [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
}
@end
@implementation NSDictionary (JSON)
- (NSData *)jsonData {
return [NSJSONSerialization dataWithJSONObject:self options:0 error:nil];
}
- (NSString *)jsonString {
return [[NSString alloc] initWithData:[self jsonData] encoding:NSUTF8StringEncoding];
}
@end
@implementation NSArray (JSON)
- (NSData *)jsonData {
return [NSJSONSerialization dataWithJSONObject:self options:0 error:nil];
}
- (NSString *)jsonString {
return [[NSString alloc] initWithData:[self jsonData] encoding:NSUTF8StringEncoding];
}
@end