我有一個問題,字典timeStamps
將所有數值以null
。鑰匙都很好,即使我把鑰匙轉換成價值,反之亦然。無論訂單如何,數值最終爲null
,並且鍵完全按照他們的要求結束。添加鍵/值對結果與空鍵的值
這是代碼。這是一個XML解析器。它正在構建一個字典,其中包含一組用於鍵的代碼和一組值的時間戳。鍵和值是表示類別的平行數組。
所有變量分配和其他地方開始。這會導入包含所有這些變量作爲屬性的頭文件。 @property (strong, nonatomic) Type variableName;
然後在主文件中它有行@synthesize variableName
。另外,它有variableName = [[Type alloc] init];
。謝謝大家的幫助!
- (void) didStartElement (elementname is passed as xml tag)
{
//Tells us if we are in the dance categories
if ([elementName isEqualToString:@"categories"])
{
isCategory = YES; // Just tells us we're ready to start reading
}
else if ([elementName isEqualToString:@"category"] && isCategory)
{
onCategory = YES; //
}
}
- (void) foundCharacters (currentNodeContent is the info between tags)
{
currentNodeContent = (NSMutableString *) string;
}
- (void) didEndElement
{
// if leaving dance categories
if ([elementName isEqualToString:@"Category End"])
{
isCategory = NO; // We've left a category
}
else if ([elementName isEqualToString:@"code"] && onCategory)
{
Code = currentNodeContent;
currentNodeContent = nil;
isWaitingForTime = YES;
}
else if ([elementName isEqualToString:@"time"] && isWaitingForTime)
{
[runningList addObject:Code];
[runningList addObject:currentNodeContent];
isWaitingForTime = NO;
currentNodeContent = nil;
Code = @"";
}
else if ([elementName isEqualToString:@"dances"])
{
[timeStamps setObject:runningTimeList forKey:runningList];
[runningTimeList removeAllObjects];
[runningList removeAllObjects];
}
}
你真的實例化了數組嗎? – Wain
作爲背景,爲什麼你使用字符串*數組作爲你的鍵和值類型?或者你想他們只是字符串? – CRD
由於您從未實際創建過字典,因此從字典中提取值的調用返回nil。 –