感谢您在以下方面提供任何帮助:
我正在加载以下 JSON 数据..
(
{
name = Facilities;
versiondate = "1972-01-01";
},
{
name = Services;
versiondate = "1972-01-01";
},
{
name = ThingsToDo;
versiondate = "1972-01-01";
}
)
进入以下代码:
NSMutableDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:updateData options:kNilOptions error:&errorString];
然后,我尝试遍历 Dictionary 并尝试将versiondate更改为今天的日期。我花了两个多小时试图做到这一点......但没有运气!我正在努力理解 MutableCopies 等。我在这方面相对较新......
所以,我正在尝试以下操作:
for (NSMutableDictionary *item in dictionary)
{
NSMutableDictionary *newdict = [item mutableCopy];
NSLog(@"I have item as: %@",newdict);
NSLog(@"I have the date as: %@", [newdict objectForKey:@"versiondate"]);
[newdict setObject:[NSDate date] forKey:@"versiondate"];
NSLog(@"I now have the date as: %@", [newdict objectForKey:@"versiondate"]);
NSLog(@"I have item as: %@",newdict);
item = newdict;
}
NSLog(@"New Dictionary now becomes: %@", dictionary);
并且忽略 NSLog 的东西,我没有运气。我只是想将versiondate更改为今天的日期,然后为每个versiondate保存它。叹。
任何帮助告诉我我的“明显”错误在哪里将不胜感激。我将 item 声明为 NSMutableDictionary ...那么为什么我必须定义newdict?一旦我更新了值,我如何将它“保存”回我原来的字典中?