iphone - xcode 计算 JSON 项目

标签 iphone ios xcode json

我需要计算此 JSON 响应中的项目(帖子)数量,

2012-06-04 14:09:57.872 horitable[72261:11903] JSON : {
posts =     (
            {
        post =             {
            eventdate = "2012-03-31";
            eventid = 2;
            eventimage = "http://hernandoz.local/~hernandoz/kopict/02_31march2012.jpg";
            eventinfo = "02 event";
            eventname = "xplosion 02";
        };
    },
            {
        post =             {
            eventdate = "2012-07-07";
            eventid = 3;
            eventimage = "http://hernandoz.local/~hernandoz/kopict/greg_vs_turner.jpg";
            eventinfo = "02 event";
            eventname = "Xplosion 02";
        };
    },
            {
        post =             {
            eventdate = "2012-04-29";
            eventid = 4;
            eventimage = "http://hernandoz.local/~hernandoz/kopict/ko_itclub_apr_2012.jpg";
            eventinfo = "KO East London Interclub";
            eventname = "KO Interclub";
        };
    }
);

}

我知道只有 3 个事件(发布),这是我正在使用的代码

 [[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
    NSLog(@"JSON : %@", JSON); //get the JSON response

    // 6.1 - Load JSON into internal variable
    jsonResponse = JSON;
    // 6.2 - Get the number of shows (post)
    int shows = 0;
    for (NSDictionary* day in jsonResponse) {
        shows += [[day objectForKey:@"posts"] count];

        NSLog(@"count : %d",shows);
    }

我收到错误,但我不明白为什么。

-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x76986f0

有人可以帮我吗?谢谢

最佳答案

试试这个

NSLog(@"Response members= %@",responseString);
NSArray *array = [(NSDictionary*)[responseString JSONValue] objectForKey:@"posts"];
NSLog(@"Count value= %d",[array count]);    

关于iphone - xcode 计算 JSON 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10882060/

相关文章:

iphone - 关闭 UIViewController 后向parentViewController发送消息

iphone - 确定用户是否拒绝了 CoreLocation 权限

iphone - 涉及新实体和一对多关系的核心数据迁移

iOS 电池电量在后台时不会改变

c# - 在 Unity 中构建和加载 Assetbundle

xcode - 使用未声明类型 FBRequest

javascript - 将触摸事件分配给 Canvas 中的元素 - iPad

android - ZeroBrane DebugServer 连接被拒绝

iphone - 你能在 Cocoa Touch 中获得系统接听电话按钮吗?

xcode - react 原生 clang : error: linker command failed with exit code 1