TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Apr 2017 |
Maintained by mkoosun.
Convenient and Simple Data Modeling Framework for JSON - Very useful for network protocol,and support inheritance, nesting.
copy
NSObject+JsonImpl.h
andNSObject+JsonImpl.m
to your projext.
or
JsonImpl is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "JsonImpl"
To run the example project, clone the repo, and run pod install
from the Example directory first.
@interface Human : NSObject
@property (nonatomic, assign) NSInteger age;
@end
...
NSDictionary *dict = @{@"age":@30};
Human *man = [Human new];
[man parse:dict];
NSString *jsonStr = @"{\n \"age\" : 30\n}";
Man *man2 = [Man new];
[man2 parse: jsonStr];
Human *man = [Human new];
NSString *str = [man toJsonString];
NSDictionary *dict = [man toJsonDictionary];
@interface Man : Human
@property (nonatomic, strong) NSString *job;
@end
@interface Man : Human
@property (nonatomic, strong) Human* wife;
@end
@interface Man : Human
@property (nonatomic, strong) NSArray* childrens;
@end
@implementation Man
+ (void)initialize
{
if (self == [Man class]) {
[self setArrayProperty:@"childrens" withClass:@"Human"];
}
}
if property name is end of '_ignore', the property will be ignored
if you setIgnoreProperty
in initialize
, the property will be ignored
if the property contain <Ignore>
, also will be ignored
@interface Man : Human
@property (nonatomic, strong) NSString<Ignore>* stringProperty;
@property (nonatomic, strong) NSString* stringProperty_ignore;
@property (nonatomic, assign) NSInteger intProperty;
@end
@implementation Man
+ (void)initialize
{
if (self == [Man class]) {
[self setIgnoreProperty:@"intProperty"];
}
}
@end
wanglin.sun, [email protected]
JsonImpl is available under the MIT license. See the LICENSE file for more info.