在我們的代碼中執行以下操作:如何在initWithContentsOfFile時阻止NSMutableDictionary將我的長NSString轉換爲NSNumber?
- (void) createComment:(NSString *)comment ForId:(NSString *)objectId
{
[facebookArguments setObject:objectId forKey:FACEBOOK_COMMENTS_FOR_ID_KEY ];
[facebookArguments setObject:comment forKey:FACEBOOK_COMMENTS_FOR_ID_COMMENT];
[facebookPrefs writeToFile:facebookPrefsFilePath atomically: NO];
[facebookArguments writeToFile:facebookArgumentsFilePath atomically:NO];
}
但在調用此代碼:
NSMutableDictionary* fbArgsDic = [[NSMutableDictionary alloc] initWithContentsOfFile: facebookArgumentsFilePath];
NSLog(@"Dictionary: %@", fbArgsDic);
這裏的日誌輸出前:
2011-08-04 16:11:53.938 My_App[30909:207] Dictionary: {
facebookGetCommentsForIdComment = Legend;
facebookGetCommentsForIdKey = 10150249987646875;
facebookLikeForIdKey = 10150249445616875;
}
後:
2011-08-04 16:06:39.685 My_App[30693:207] Dictionary: {
facebookGetCommentsForIdComment = Legend;
facebookGetCommentsForIdKey = "1.015024998764688e+16";
facebookLikeForIdKey = 10150249445616875;
}
它將FACEBOOK_COMMENTS_FOR_ID_KEY項(如上所示爲NSString)轉換爲NSNumber並丟失了一些數字。這些是LONG號碼,因爲它們是Facebook的ID。
任何想法發生了什麼以及我們如何解決它?
你爲什麼不張貼日誌輸出?還有一個示例ID。 – Joe
我想你不應該調用那個字符串'id',因爲它是一個保留關鍵字。不知道這是否是問題,雖然 – andreamazz
我認爲'facebookGetCommentsForIdKey'字典是autoreleased。試用'保留'?? – Hisenberg