如何获取数组值计数?

时间:2014-09-18 11:12:43

标签: ios objective-c json

我需要获得JSON响应数组" A" [值计数]。下面我发布了我的JSON响应。请帮我。

response : [ {

        A =  [  {

                    name : "sons";
                    age = [
                                4
                          ];
                },
                {
                    name : "rondo";
                    age = [
                                2
                          ];
                },

             ];


           } ]



NSArray *firstObject = @"A";
NSArray *count = [[[responsData objectAtIndex:0] objectForKey:firstObject]valueForKey:@"name"];

下面是我当前的控制台输出:

2014-09-18 16:32:36.746 Myapp[4243:60b] TEST   : (
    sons,
    rondo
)

我需要如下所示"名称值计数"

2014-09-18 16:32:36.746 Myapp[4243:60b] TEST   : (

     2
)

1 个答案:

答案 0 :(得分:0)

试试这个:

     NSArray *count = [[[responsData objectAtIndex:0] objectForKey:firstObject]valueForKey:@"name"];
     NSLog(@"count == %d",[count count]);