7
7
//
8
8
9
9
#import " NSObject+MCJSONKit.h"
10
- #import " MCJSONKitProperty.h"
11
10
#import " NSDictionary+MCJSONKit.h"
12
11
13
12
#import < objc/runtime.h>
@@ -119,8 +118,8 @@ - (void)setValuesWithJSONString:(NSString *)jsonString {
119
118
120
119
- (void )setValuesWithDictionary : (NSDictionary *)dict {
121
120
if (dict && [dict isKindOfClass: [NSDictionary class ]]) {
122
- NSMutableDictionary <NSString *,JSONCoreProperty *> *mdict = [self allProperties ];
123
- [mdict enumerateKeysAndObjectsUsingBlock: ^(NSString * _Nonnull key, JSONCoreProperty * _Nonnull obj, BOOL * _Nonnull stop) {
121
+ NSMutableDictionary <NSString *,MCJSONKitProperty *> *mdict = [self allProperties ];
122
+ [mdict enumerateKeysAndObjectsUsingBlock: ^(NSString * _Nonnull key, MCJSONKitProperty * _Nonnull obj, BOOL * _Nonnull stop) {
124
123
if ([obj.jsonKey rangeOfString: @" ." ].location == NSNotFound ) {
125
124
[self setValue: dict[obj.jsonKey] forProperty: obj];
126
125
}else {
@@ -137,7 +136,7 @@ - (void)setValuesWithDictionary:(NSDictionary *)dict {
137
136
/* *
138
137
设置属性值
139
138
*/
140
- - (void )setValue : (id )value forProperty : (JSONCoreProperty *)property {
139
+ - (void )setValue : (id )value forProperty : (MCJSONKitProperty *)property {
141
140
if ([value isKindOfClass: [NSNull class ]]) {
142
141
// NSNull不做处理
143
142
return ;
@@ -160,7 +159,8 @@ - (void)setValue:(id)value forProperty:(JSONCoreProperty *)property {
160
159
}
161
160
[self setValue: newValue forKey: property.name];
162
161
}
163
- }else {
162
+ } else {
163
+ value = [self mc_newValueFromOldValue: value property: property];
164
164
if ([value isKindOfClass: [NSNumber class ]]) {
165
165
if ([property.typeClass isSubclassOfClass: [NSString class ]]) {
166
166
// 属性是NSString,但是值类型为NSNumber
@@ -197,7 +197,7 @@ - (void)setValue:(id)value forProperty:(JSONCoreProperty *)property {
197
197
}
198
198
}
199
199
200
- - (id )valueForProperty : (JSONCoreProperty *)property {
200
+ - (id )valueForProperty : (MCJSONKitProperty *)property {
201
201
if (property) {
202
202
id value = [self valueForKey: property.name];
203
203
if (property.typeClass ) {
@@ -283,7 +283,7 @@ - (NSMutableDictionary *)allProperties {
283
283
}
284
284
285
285
// 类型说明
286
- JSONCoreProperty *coprop = [JSONCoreProperty new ];
286
+ MCJSONKitProperty *coprop = [MCJSONKitProperty new ];
287
287
coprop.name = propertyName;
288
288
289
289
// 自定义映射
@@ -347,9 +347,9 @@ - (NSDictionary *)mc_toDictionary {
347
347
return jsonObj;
348
348
}
349
349
350
- NSDictionary <NSString *,JSONCoreProperty *> *dict = [self allProperties ];
350
+ NSDictionary <NSString *,MCJSONKitProperty *> *dict = [self allProperties ];
351
351
NSMutableDictionary *mdict = [NSMutableDictionary dictionary ];
352
- [dict enumerateKeysAndObjectsUsingBlock: ^(NSString * _Nonnull key, JSONCoreProperty * _Nonnull obj, BOOL * _Nonnull stop) {
352
+ [dict enumerateKeysAndObjectsUsingBlock: ^(NSString * _Nonnull key, MCJSONKitProperty * _Nonnull obj, BOOL * _Nonnull stop) {
353
353
void (^setValueBlock)(id ) = ^(id value) {
354
354
if (value) {
355
355
[mdict setValue: value forKeyPath: obj.jsonKey];
@@ -414,4 +414,8 @@ - (NSDictionary *)mc_typeMappingDictionary {
414
414
return nil ;
415
415
}
416
416
417
+ - (id )mc_newValueFromOldValue : (id )oldValue property : (MCJSONKitProperty *)property {
418
+ return oldValue;
419
+ }
420
+
417
421
@end
0 commit comments