当我的NSLog影响日期值时,它显示正确,但当我将其存储在var中时,它会给出错误的值
SBJsonParser *parser= [[SBJsonParser alloc] init];
NSString *url = [NSString stringWithFormat:@"http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=%@&counties-selected=Vest-Agder,Aust-Agder&range=0-10", test];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSDictionary *object = [parser objectWithString:json_string error:nil];
NSArray *results = [parser objectWithString:json_string error:nil];
appDelegate.books1 = [[NSMutableArray alloc] init];
appDelegate.dates =[[NSMutableArray alloc]init];
appDelegate.books2=[[NSMutableArray alloc]init];
appDelegate.books3=[[NSMutableArray alloc]init];
appDelegate.books4=[[NSMutableArray alloc]init];
appDelegate.books5=[[NSMutableArray alloc]init];
appDelegate.books6=[[NSMutableArray alloc]init];
appDelegate.books7=[[NSMutableArray alloc]init];
appDelegate.books8=[[NSMutableArray alloc]init];
appDelegate.books9=[[NSMutableArray alloc]init];
appDelegate.books10=[[NSMutableArray alloc]init];
NSArray *activitiesArray;
mycount=[results count];
for (int j=0;j<[results count]; j++) {
NSDictionary *dictOne = [results objectAtIndex:j];
NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
Date *aDate = [[Date alloc] initWithDictionary:[results objectAtIndex:j]];
[appDelegate.dates addObject:aDate];
[aDate release];
activitiesArray = [dictOne objectForKey:@"events"];
for (int i=0; i<[activitiesArray count]; i++) {
int testcount =[activitiesArray count];
NSDictionary *dictTwo = [activitiesArray objectAtIndex:i];
NSDictionary *eventDict=[dictTwo objectForKey:@"event"];
// NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
// NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
// NSLog(@"%@ - %@", [eventDict objectForKey:@"location"]);
NSInteger*date=[dictTwo objectForKey:@"affectedDate"];
NSInteger*affecteddate=[dictTwo objectForKey:@"affectedDate"];
NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
NSString*appId =[eventDict objectForKey:@"appId"];
NSLog(@"%@ - %@", [eventDict objectForKey:@"eventId"]);
NSInteger*eventId=[eventDict objectForKey:@"eventId"];
int next=[affecteddate intValue];
int next_int = [eventId intValue];
NSString*location=[eventDict objectForKey:@"location"];
NSString*municipality=[eventDict objectForKey:@"municipality"];
NSString*title=[eventDict objectForKey:@"title"];
Book1 *aBook=[[Book1 alloc] initWithDate:date affecteddate:affecteddate eventId:eventId location:location municipality:municipality title:title];
Book1课程 @interface Book1:NSObject { NSInteger的*日期; NSInteger的* affecteddate;
NSString *title;
NSString *location;
NSString *municipality;
NSInteger eventId;
NSString* event;
}
@property(nonatomic,readwrite) NSInteger eventId;
@property(nonatomic,retain) NSString* event;
@property(nonatomic) NSInteger *date;
@property(nonatomic,readwrite)NSInteger* affecteddate;
@property(nonatomic,retain)NSString *title;
@property(nonatomic,retain) NSString *location;
@property(nonatomic,retain) NSString *municipality;
-(id)initWithDate:(NSInteger *)d affecteddate:(NSInteger *)ad eventId:(NSInteger*)eId location:(NSString *)l municipality:(NSString *)m title:(NSString *)t ;
@end
答案 0 :(得分:0)
首先你有:
NSInteger*affecteddate=[dictTwo objectForKey:@"affectedDate"];
后
int next=[affecteddate intValue];
intValue
对整数
你可能想要:
NSNumber *date = [dictTwo objectForKey:@"affectedDate"];
NSNumber *affecteddate = [dictTwo objectForKey:@"affectedDate"];
可以在book对象中声明为此值
NSNumber *affecteddate;
@propert(nonatomic,retain)