我是 ios 编程的新手。我将我的数据放在 NSDictionary 中,然后在将其发送到服务器之前使用 AFJSONRequestSerializer 序列化为 json。
现在,如果我的 json 具有简单的结构,如键 -> 值对,那么我可以轻松做到,但如果我的结构是这样的 -
"person" = (
{
"location" = {
city = "Manila";
Country = "Phillipines";
};
image = "http://mymanila.com/1.png";
link ="http://mymanila.com/1.html"
}
);
我的问题是如何放置位置,它本身是另一个具有键值对的字典?谢谢。
最佳答案
给你。
NSDictionary *locationDictionary = @
{
@"city" : @"Manila",
@"Country" : @"Phillipines"
};
NSDictionary *personDictionary = @
{
@"location" : locationDictionary,
@"image" : @"http://mymanila.com/1.png",
@"link" : @"http://mymanila.com/1.html"
};
NSDictionary *fullDictionary = @
{
@"person" : personDictionary
};
现在,只需序列化 fullDictionary
。
关于ios - 如何在序列化为 json 之前将 NSDictionary 添加到另一个 NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24921704/