我嘗試通過將字典作爲參數傳入方法來將字典插入到字典中。我有一個包含字典的鍵0,1,2,...,6的字典,我嘗試在新字典中使用鍵0獲取字典,但新字典爲零。試試在字典中插入字典返回零
dictionaryWithWeekDays包括這樣的事情:
0 = {
clouds = 0;
deg = 239;
dt = 1475175600;
humidity = 76;
pressure = "993.71";
speed = "3.24";
temp = {
day = "70.09";
eve = "74.73";
max = "76.64";
min = "51.53";
morn = "54.66";
night = "51.53";
};
weather = (
{
description = "light rain";
icon = 10d;
id = 500;
main = Rain;
}
);
};
1 = {
clouds = 12;
deg = 337;
dt = 1475607600;
humidity = 0;
pressure = "1012.86";
speed = "3.89";
temp = {
day = "59.59";
eve = "64.56";
max = "64.56";
min = "49.64";
morn = "49.64";
night = "54.32";
};
weather = (
{
description = "light rain";
icon = 10d;
id = 500;
main = Rain;
}
);
};
我有一個循環,因爲要傳遞的所有鍵的方法。我只是叫我的方法引入循環是這樣的:
for (int i = 0; i <= 6; i++) {
NSString *key = [NSString stringWithFormat:@"%i", i];
[self addValuesToArrayWithTemp:dictionaryWithWeekDays key:key index:i];
}
這裏是我的addValuesToArrayWithTemp:
-(void) addValuesToArrayWithTemp:(NSDictionary *)inputDic key:(NSString *)key index:(int)ind {
NSDictionary *currentDic = [inputDic objectForKey:key];
NSLog(@"currentDic = %@", currentDic);
NSLog(@"key = %@", key);
...
...
}
(NSDictionary *)inputDic
- 是確定它包括所有我面前經過,關鍵還好吧有@ 「0」值。但是currentDic是零。爲什麼??也許我誤解了一些東西。感謝幫助!
在調用'addValues之前,你能否一次檢查''key'的'dictionaryWithWeekDays'是否有一些值,並在這裏發表你的發現。 – prabodhprakash
你可以顯示代碼如何生成此字典 –
也試試這一次'[inputDic objectForKey:@ 0];' –