Skip to content

Commit 55df9f2

Browse files
author
jueying
committed
NSArray support for jk_JSONString.
1 parent 36f5c8d commit 55df9f2

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

JKCategories-Demo.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/* End PBXAggregateTarget section */
2222

2323
/* Begin PBXBuildFile section */
24+
8C92BBBD248E30D9008D5E94 /* NSArray+JKJSONString.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C92BBBB248E30D9008D5E94 /* NSArray+JKJSONString.h */; };
25+
8C92BBBE248E30D9008D5E94 /* NSArray+JKJSONString.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C92BBBC248E30D9008D5E94 /* NSArray+JKJSONString.m */; };
2426
A202D9801B0F7CD100EAB199 /* CLLocationDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A202D97E1B0F7CD100EAB199 /* CLLocationDemoViewController.m */; };
2527
A202D9811B0F7CD100EAB199 /* CLLocationDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A202D97F1B0F7CD100EAB199 /* CLLocationDemoViewController.xib */; };
2628
A202D98C1B0F7D7900EAB199 /* MKMapViewDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A202D98A1B0F7D7900EAB199 /* MKMapViewDemoViewController.m */; };
@@ -598,6 +600,8 @@
598600
/* Begin PBXFileReference section */
599601
798256181B3A59060033A0C1 /* NSString+JKNormalRegex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+JKNormalRegex.h"; sourceTree = "<group>"; };
600602
798256191B3A59060033A0C1 /* NSString+JKNormalRegex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+JKNormalRegex.m"; sourceTree = "<group>"; };
603+
8C92BBBB248E30D9008D5E94 /* NSArray+JKJSONString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+JKJSONString.h"; sourceTree = "<group>"; };
604+
8C92BBBC248E30D9008D5E94 /* NSArray+JKJSONString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+JKJSONString.m"; sourceTree = "<group>"; };
601605
A202D9601B0F6C4400EAB199 /* NSDate+JKReporting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+JKReporting.h"; sourceTree = "<group>"; };
602606
A202D9611B0F6C4400EAB199 /* NSDate+JKReporting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+JKReporting.m"; sourceTree = "<group>"; };
603607
A202D9631B0F6DF900EAB199 /* NSString+JKMIME.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+JKMIME.h"; sourceTree = "<group>"; };
@@ -2610,6 +2614,8 @@
26102614
A28BE34C1A3EA8B0005C4AC6 /* NSArray */ = {
26112615
isa = PBXGroup;
26122616
children = (
2617+
8C92BBBB248E30D9008D5E94 /* NSArray+JKJSONString.h */,
2618+
8C92BBBC248E30D9008D5E94 /* NSArray+JKJSONString.m */,
26132619
A28BE3501A3EA91B005C4AC6 /* NSArray+JKBlock.h */,
26142620
A28BE3511A3EA91B005C4AC6 /* NSArray+JKBlock.m */,
26152621
A2EC52E51A8769D40059D53B /* NSArray+JKSafeAccess.h */,
@@ -3258,6 +3264,7 @@
32583264
B81025F6206A11650099CDA8 /* UIView+JKDraggable.h in Headers */,
32593265
B8C46B52216F119A00EC7F15 /* JKQuartzCore.h in Headers */,
32603266
B8C46B58216F11B200EC7F15 /* JKUIKit.h in Headers */,
3267+
8C92BBBD248E30D9008D5E94 /* NSArray+JKJSONString.h in Headers */,
32613268
B8C46B5A216F11BA00EC7F15 /* JKMapKit.h in Headers */,
32623269
B8C46B56216F11AA00EC7F15 /* JKFoundation.h in Headers */,
32633270
B8C46B5C216F11C000EC7F15 /* JKCoreLocation.h in Headers */,
@@ -3673,6 +3680,7 @@
36733680
B8102500206A10390099CDA8 /* NSData+JKAPNSToken.m in Sources */,
36743681
B81024D5206A100E0099CDA8 /* NSUserDefaults+JKSafeAccess.m in Sources */,
36753682
B810248F206A0F7D0099CDA8 /* CATransaction+JKAnimateWithDuration.m in Sources */,
3683+
8C92BBBE248E30D9008D5E94 /* NSArray+JKJSONString.m in Sources */,
36763684
B8102601206A11720099CDA8 /* UIView+JKNib.m in Sources */,
36773685
B81024D7206A100E0099CDA8 /* NSIndexPath+JKOffset.m in Sources */,
36783686
B81025DD206A11470099CDA8 /* UIImage+JKCapture.m in Sources */,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// NSArray+JKJSONString.h
3+
// JKCategories
4+
//
5+
// Created by jueying on 2020/5/27.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface NSArray (JKJSONString)
13+
14+
/**
15+
* @brief NSArray转换成JSON字符串
16+
*
17+
* @return JSON字符串
18+
*/
19+
- (NSString *)jk_JSONString;
20+
21+
@end
22+
23+
NS_ASSUME_NONNULL_END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// NSArray+JKJSONString.m
3+
// JKCategories
4+
//
5+
// Created by jueying on 2020/5/27.
6+
//
7+
8+
#import "NSArray+JKJSONString.h"
9+
10+
@implementation NSArray (JKJSONString)
11+
12+
/**
13+
* @brief NSArray转换成JSON字符串
14+
*
15+
* @return JSON字符串
16+
*/
17+
- (NSString *)jk_JSONString {
18+
NSError *error = nil;
19+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
20+
options:NSJSONWritingPrettyPrinted
21+
error:&error];
22+
if (jsonData == nil) {
23+
#ifdef DEBUG
24+
NSLog(@"fail to get JSON from dictionary: %@, error: %@", self, error);
25+
#endif
26+
return nil;
27+
}
28+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
29+
return jsonString;
30+
}
31+
32+
@end

0 commit comments

Comments
 (0)