-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jueying
committed
Jun 8, 2020
1 parent
36f5c8d
commit 55df9f2
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// NSArray+JKJSONString.h | ||
// JKCategories | ||
// | ||
// Created by jueying on 2020/5/27. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSArray (JKJSONString) | ||
|
||
/** | ||
* @brief NSArray转换成JSON字符串 | ||
* | ||
* @return JSON字符串 | ||
*/ | ||
- (NSString *)jk_JSONString; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// NSArray+JKJSONString.m | ||
// JKCategories | ||
// | ||
// Created by jueying on 2020/5/27. | ||
// | ||
|
||
#import "NSArray+JKJSONString.h" | ||
|
||
@implementation NSArray (JKJSONString) | ||
|
||
/** | ||
* @brief NSArray转换成JSON字符串 | ||
* | ||
* @return JSON字符串 | ||
*/ | ||
- (NSString *)jk_JSONString { | ||
NSError *error = nil; | ||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self | ||
options:NSJSONWritingPrettyPrinted | ||
error:&error]; | ||
if (jsonData == nil) { | ||
#ifdef DEBUG | ||
NSLog(@"fail to get JSON from dictionary: %@, error: %@", self, error); | ||
#endif | ||
return nil; | ||
} | ||
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | ||
return jsonString; | ||
} | ||
|
||
@end |