0
編輯:10年10月9日
我覺得當JSON庫試圖解析使用圖形API發佈的高分在Facebook上
[NSString stringWithFormat:@"%d weeks",[components week]];
我怎麼會格式化應用程序崩潰,這樣可以JSON解析它?
這裏是JSON代碼行
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",
nil];
任何人都可以點我就如何做到這一點的教程?我可以在下面的代碼塊中輕鬆發佈靜態文本,但我無法將NSString
與動態數據集成,但它不會顯示在Fb帖子附件部分。
NSDictionary *attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"Testing", @"name",
@"testing2", @"caption",
[NSString stringWithFormat:@"%d weeks",[components week]], @"description"//Xcode says components undeclared
//highscore, @"description", //here's the problem, highscore is the NSString variable.
@"http://testing.com/", @"href", nil];
更新: 問題是我使用的字符串是從放2周差和出的時間間隔[components week]
然後xcode的告訴我,組件是一個未聲明的變量
[NSString stringWithFormat:@"%d weeks",[components week]]
這裏是整個日期代碼塊,我得到上面的字符串從:
NSString *dateStr = @"20100716";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *startDate = [dateFormat dateFromString:dateStr];
NSDate *endDate = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSWeekCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:startDate
toDate:endDate options:0];
NSInteger weeks = [components week];
NSInteger days = [components day];
我試過這個字符串格式,它只是崩潰的應用程序 – BigB 2010-10-09 21:32:53