//
//  NewsData.m
//  Apex Mobile
//
//  Created by Ray on 14-4-21.
//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
//

#import "NewsData.h"

@implementation NewsData
-(id)init : (int) limit
{
    self = [super init];
    if(self)
    {
        self.pagedata =  [[NSMutableArray alloc]init];
        self.limit = limit;
        self.finishload = false;
    }
    return self;
}
-(void) appenddata : (NSData*) data
{
    NSError *error=nil;
    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
    if(jsobj)
    {
        int count =  [[jsobj valueForKey:@"total" ] intValue];
        if(count<self.limit)
            self.finishload = true;
        NSDictionary * objrecords = [jsobj objectForKey:@"records"];
        for(int i=0;i<count;i++)
        {
            NSDictionary* objrec = [objrecords objectForKey:[NSString stringWithFormat:@"record%d",i ]];
//            NSString* title = [objrec valueForKey:@"title"];
//            NSString* content  = [objrec valueForKey:@"content"];
//            NSString* image  = [objrec valueForKey:@"image"];
//            NSString* _id  = [objrec valueForKey:@"id"];
//            NSString* url  = [objrec valueForKey:@"url"];
//            
//            NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
//            map setValue:title forKey:@"title"
            self._id =[objrec valueForKey:@"id"];
            [self.pagedata addObject:objrec];
            
        }
        
    }
    
    
}
-(long) get_count
{
    return self.pagedata.count;
}
@end
