forked from ibireme/YYModel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYYTestHelper.m
43 lines (34 loc) · 1.18 KB
/
YYTestHelper.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
//
// YYTestHelper.m
// YYModel <https://github.com/ibireme/YYModel>
//
// Created by ibireme on 15/11/28.
// Copyright (c) 2015 ibireme.
//
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "YYTestHelper.h"
@implementation YYTestHelper
+ (NSString *)jsonStringFromData:(NSData *)data {
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
+ (NSString *)jsonStringFromObject:(id)object {
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:NULL];
return [self jsonStringFromData:data];
}
+ (id)jsonObjectFromData:(NSData *)data {
return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:NULL];
}
+ (id)jsonObjectFromString:(NSString *)string {
NSData *data = [self jsonDataFromString:string];
return [self jsonObjectFromData:data];
}
+ (NSData *)jsonDataFromString:(NSString *)string {
return [string dataUsingEncoding:NSUTF8StringEncoding];
}
+ (NSData *)jsonDataFromObject:(id)object {
NSString *string = [self jsonStringFromObject:object];
return [self jsonDataFromString:string];
}
@end