2013-04-26 38 views
0

不管项目的数量在我的阵列,count总是返回1 的_contentData阵列来自JSON响应:计数多维数组始终返回1

_contentData = [[NSMutableArray alloc] initWithObjects:JSON, nil]; 

阵列(_contentData):

(
     (
      { 
      id = 1; 
      name = "Entry 1"; 
      }, 
      { 
      id = 2; 
      name = "Entry 2"; 
      }, 
      { 
      id = 3; 
      name = "Entry 3"; 
      } 
     ) 
    ) 

代码:

NSLog(@"%lu", (unsigned long)_contentData.count); 

输出:

2013-04-26 18:32:00.968 SP[23542:c07] 1 

回答

1

您的数组中的第一个对象是另一个数组,所以你的计数总是1试试这个:

NSLog(@"%lu", (unsigned long)[_contentData[0] count]); 
+0

错误:'住宅“数”上找不到对象键入'id''。我解析Json到Array的方式是正确的? – 2013-04-26 21:58:15

+1

不,只是编译器不知道'_contentData [0]'是一个数组。我编辑了代码,尝试更新后的版本。 – 2013-04-29 00:26:16