@@ -187,6 +187,27 @@ -(id)getNodeValue:(NSString *)node fromXML:(NSString *)xml {
187
187
}
188
188
189
189
#pragma mark - Dictionary to Object
190
+ + (NSDate *)p_dateFromObj : (id )obj {
191
+ NSDate *date;
192
+ if ([obj isKindOfClass: [NSNumber class ]]) {
193
+ // 1970年的long型数字
194
+ NSNumber *timeSince1970 = (NSNumber *)obj;
195
+ NSTimeInterval timeSince1970TimeInterval = timeSince1970.doubleValue /1000 ;
196
+ date = [NSDate dateWithTimeIntervalSince1970: timeSince1970TimeInterval];
197
+ }else if ([obj isKindOfClass: [NSString class ]]){
198
+ // 日期字符串
199
+ NSDateFormatter *formatter = [[NSDateFormatter alloc ] init ];
200
+ [formatter setDateFormat: OMDateFormat];
201
+ [formatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation: OMTimeZone]];
202
+ date = [formatter dateFromString: (NSString *)obj];
203
+ if (!date) {
204
+ [formatter setDateFormat: EADateFormat];
205
+ date = [formatter dateFromString: (NSString *)obj];
206
+ }
207
+ }
208
+ return date;
209
+ }
210
+
190
211
+(id )objectOfClass : (NSString *)object fromJSON : (NSDictionary *)dict {
191
212
if (!dict || ![dict isKindOfClass: [NSDictionary class ]]) {
192
213
return nil ;
@@ -231,21 +252,7 @@ +(id)objectOfClass:(NSString *)object fromJSON:(NSDictionary *)dict {
231
252
232
253
// check if NSDate or not
233
254
if ([classType isEqualToString: @" T@\" NSDate\" " ]) {
234
- // 1970年的long型数字
235
- NSObject *obj = [dict objectForKey: key];
236
- if ([obj isKindOfClass: [NSNumber class ]]) {
237
- NSNumber *timeSince1970 = (NSNumber *)obj;
238
- NSTimeInterval timeSince1970TimeInterval = timeSince1970.doubleValue /1000 ;
239
- NSDate *date = [NSDate dateWithTimeIntervalSince1970: timeSince1970TimeInterval];
240
- [newObject setValue: date forKey: propertyName];
241
- }else {
242
- // 日期字符串
243
- NSDateFormatter *formatter = [[NSDateFormatter alloc ] init ];
244
- [formatter setDateFormat: OMDateFormat];
245
- [formatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation: OMTimeZone]];
246
- NSString *dateString = [[dict objectForKey: key] stringByReplacingOccurrencesOfString: @" T" withString: @" " ];
247
- [newObject setValue: [formatter dateFromString: dateString] forKey: propertyName];
248
- }
255
+ [newObject setValue: [self p_dateFromObj: [dict objectForKey: key]] forKey: propertyName];
249
256
}
250
257
else {
251
258
if ([dict objectForKey: key] != [NSNull null ]) {
@@ -370,22 +377,7 @@ +(NSMutableArray *)arrayMapFromArray:(NSArray *)nestedArray forPropertyName:(NSS
370
377
NSString *classType = [self typeFromProperty: property];
371
378
// check if NSDate or not
372
379
if ([classType isEqualToString: @" T@\" NSDate\" " ]) {
373
- // 1970年的long型数字
374
- NSObject *obj = [nestedArray[xx] objectForKey: newKey];
375
- if ([obj isKindOfClass: [NSNumber class ]]) {
376
- NSNumber *timeSince1970 = (NSNumber *)obj;
377
- NSTimeInterval timeSince1970TimeInterval = timeSince1970.doubleValue /1000 ;
378
- NSDate *date = [NSDate dateWithTimeIntervalSince1970: timeSince1970TimeInterval];
379
- [nestedObj setValue: date forKey: tempNewKey];
380
- }else {
381
- // 日期字符串
382
- NSDateFormatter *formatter = [[NSDateFormatter alloc ] init ];
383
- [formatter setDateFormat: OMDateFormat];
384
- [formatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation: OMTimeZone]];
385
-
386
- NSString *dateString = [[nestedArray[xx] objectForKey: newKey] stringByReplacingOccurrencesOfString: @" T" withString: @" " ];
387
- [nestedObj setValue: [formatter dateFromString: dateString] forKey: tempNewKey];
388
- }
380
+ [nestedObj setValue: [self p_dateFromObj: [nestedArray[xx] objectForKey: newKey]] forKey: tempNewKey];
389
381
}
390
382
else {
391
383
[nestedObj setValue: [nestedArray[xx] objectForKey: newKey] forKey: tempNewKey];
0 commit comments