diff options
Diffstat (limited to 'Classes/Topic.m')
-rw-r--r-- | Classes/Topic.m | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/Classes/Topic.m b/Classes/Topic.m index 1ed4420..8b7ec20 100644 --- a/Classes/Topic.m +++ b/Classes/Topic.m @@ -33,22 +33,29 @@ return topic; } -+ (Topic *) initFromJsonObject:(NSDictionary *)obj { ++ (Topic *) initWithJsonObject:(NSDictionary *)obj { Topic *topic = [[[Topic alloc] init] autorelease]; - NSDictionary *info = [obj objectForKey:@"fields"]; + //NSDictionary *info = [obj objectForKey:@"fields"]; - topic.title = [info objectForKey:@"title"]; - topic.foreignId = [obj objectForKey:@"pk"]; - topic.iconUrl = [info objectForKey:@"iconUrl"]; - topic.description = [info objectForKey:@"description"]; - topic.releaseDate = [self stringToDate:[info objectForKey:@"releaseDate"]]; - topic.category = [info objectForKey:@"category"]; - topic.picCount = [info objectForKey:@"picCount"]; + topic.title = [obj objectForKey:@"title"]; + topic.foreignId = [obj objectForKey:@"id"]; + topic.iconUrl = [self getImageUrl:[obj objectForKey:@"image"]]; + topic.description = [obj objectForKey:@"description"]; + topic.releaseDate = [NSDate dateWithTimeIntervalSince1970:[[obj objectForKey:@"created_unixtime"] doubleValue]]; + topic.category = [obj objectForKey:@"category"]; + topic.picCount = [NSNumber numberWithInt:10]; //[obj objectForKey:@"picCount"]; return topic; } ++ (NSString *) getImageUrl:(NSDictionary *)obj { + if (obj == nil || [obj class] == [NSNull class]) return nil; + else { + return [obj objectForKey:@"original_url"]; + } +} + + (NSString *) dateToString:(NSDate *)date { NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterLongStyle]; @@ -74,7 +81,7 @@ (foreignId, link, title, description, releaseDate, category, iconUrl, picCount) \ VALUES \ (?, ?, ?, ?, ?, ?, ?, ?)", - [NSNumber numberWithInt:12], guid, title, description, releaseDate, category, iconUrl, picCount]; + foreignId, guid, title, description, releaseDate, category, iconUrl, picCount]; //NSLog(@"insert id:%d error: %@", [db lastInsertRowId], [db lastErrorMessage]); // [NSString stringWithFormat:@"number %d", i], |