Objective-c:将字典的JSON数组转换为NSDictionary

jim*_*jim 2 objective-c nsdictionary

所以,我在JSON中有以下结构,我理解它是一个键/值对对象的数组:

{
"notification": [
    {
        "uid": "20",
        "count": "4"
    },
    {
        "uid": "48",
        "count": "0"
    },
    {
        "uid": "49",
        "count": "0"
    },
    {
        "uid": "53",
        "count": "0"
    }
]
}
Run Code Online (Sandbox Code Playgroud)

使用SBJson解析这将导致一组字典,每个字典具有一个键/值对.

我想将所有这些词典"内爆"到一个包含许多键/值对的字典中.顺便说一下,不要担心重复.

这是最好的方法吗?我如何遍历NSDictionary,一次访问一个项目并提取它的关键和价值?

有什么想法吗?

谢谢.

--Conor

Mun*_*ndi 7

只需遍历已存在的NSDictionarys 数组.这就是JSON的便利,您可以轻松地从Feed字符串中获取可用的数据结构.

NSArray *notifications = [[theFeedString JSONValue] objectForKey:@"notification"];  
// or whatever JSON helper you are using
for (NSDictionray *dict in notifications) {
   NSInteger uid = [[dict objectForKey:@"uid"] intValue];
   NSInteger count = [[dict objectForKey:@"count"] intValue];
   // do something with uid and count
}
Run Code Online (Sandbox Code Playgroud)