我正在制作一个从 Web 服务器获取 JSON 对象的应用程序,它是一个带有字典的字典。当我解析它时,我需要它作为字典和数组,因为我需要同时使用它们objectForKey
并objectAtIndex
动态填写我的 TableViews。
其中一些最终看起来像这样:
NSMutableArray *roomsArray = projectDict[@"rooms"];
NSMutableDictionary *roomDict = roomsArray[indexPath.row];
NSMutableArray *tasksArray = roomDict[@"tasks"];
NSMutableDictionary *task = tasksArray[indexPath.row];
NSString *status = [task objectForKey:@"status"];
因为我需要数组来获取objectAtIndex
索引indexPath.row
但是,当我在我的表格视图中单击我UISwitch
时,我需要更改 taskStatus。
但我不能,因为它不会“向上工作”。
所以,我需要:
获取 TOP 字典(projectDict)并在 1 行中,(无需按照数组和字典的顺序)替换 taskStatus。
这是我在控制台中打印的 JSON 格式的 projectDict:
projects = (
{
address = "Fugledammen 8";
city = "S\U00f8borg";
completedTasks = 0;
done = 0;
dueDate = "07/11-2013";
id = 8;
rooms = (
{
id = 9;
name = Loftet;
tasks = (
{
id = 5;
name = doSomething;
status = 0;
}
);
},
{
id = 10;
name = "v\U00e6relse 1";
tasks = (
{
id = 6;
name = doSomething;
status = 0;
}
);
}
);
totalTasks = 2;
zip = 2860;
},
{
address = "Lygten 37";
city = "K\U00f8benhavn N";
completedTasks = 0;
done = 0;
dueDate = "06/11-2013";
id = 6;
rooms = (
{
id = 2;
name = Toilet;
tasks = (
);
},
{
id = 3;
name = Kantine;
tasks = (
{
id = 2;
name = "S\U00e6tte nyt k\U00f8kken op";
status = 0;
},
{
id = 3;
name = "Ops\U00e6tte ny kaffemaskine";
status = 0;
}
);
},
{
id = 4;
name = "L\U00e6rev\U00e6relse";
tasks = (
{
id = 4;
name = "Ops\U00e6tte ny tavle";
status = 0;
}
);
}
);
totalTasks = 3;
zip = "";
},
{
address = "Tranedalen 2";
city = "Ish\U00f8j";
completedTasks = 0;
done = 0;
dueDate = "06/11-2013";
id = 5;
rooms = (
{
id = 1;
name = "K\U00f8kken";
tasks = (
);
},
{
id = 5;
name = "Badev\U00e6relse";
tasks = (
);
},
{
id = 8;
name = "Sovev\U00e6relse";
tasks = (
);
}
);
totalTasks = 0;
zip = 2635;
},
{
address = "L\U00e6rkens Kvt 30c";
city = Albertslund;
completedTasks = 1;
done = 0;
dueDate = "11/11-2013";
id = 9;
rooms = (
{
id = 11;
name = "k\U00f8kken";
tasks = (
{
id = 7;
name = "lav kaffe";
status = 1;
}
);
}
);
totalTasks = 1;
zip = 2620;
},
{
address = "S\U00f8gade 2";
city = "K\U00f8benhavn K";
completedTasks = 0;
done = 0;
dueDate = "13/11-2013";
id = 10;
rooms = (
);
totalTasks = 0;
zip = 1717;
}
);
}