在iOS中从多维数组迭代

在iOS中从多维数组迭代,ios,objective-c,arrays,uitableview,Ios,Objective C,Arrays,Uitableview,如何在iOS中从这个多维数组进行迭代? 这些数据来自JSON ( ( "burger meal", "getImage.ashx?id=1", 150, 300, "get a free burger" ), ( "chinese combo", "getImage.ashx?id=2", 350, 700,

如何在iOS中从这个多维数组进行迭代? 这些数据来自JSON

(
        (
        "burger meal",
        "getImage.ashx?id=1",
        150,
        300,
        "get a free burger"
    ),
        (
        "chinese combo",
        "getImage.ashx?id=2",
        350,
        700,
        "get  a combo free"
    ),
        (
        "cheeese cake",
        "getImage.ashx?id=3",
        350,
        700,
        "get a cake free with meal"
    )
)
我需要在UITableView中使用索引3处的对象,例如=150350350

我试过这个

NSArray *array = jsonArray;

for (NSArray *newArray in array) { 
    [newArray addObjectFromArray:array];
}

试试这个,在这段代码中,结果包含您在特定位置所需的所有值

NSArray *array = jsonArray;
NSMutableArray *arrResult = [[NSMutableArray alloc]init];

for (NSArray *newArray in array) { 
        [arrResult addObject:[newArray objectAtIndex:2]];

}

这很简单。让TableView为您迭代数组。您的tableView已经在迭代,不要通过自己迭代数组来增加开销。如果你这样做,你只会浪费处理能力

首先,修改
numberOfRowsInSection
委托方法,如下所示:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  [jsonArray count]; //Provide your json array here.
}
然后您必须在
cellforrowatinexpath
方法中执行此操作:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Do everything that you need to do to get the cell. Here we will deal with only string retrieval from json array.
    if(jsonArray count]>indexPath.row){
        NSArray *innerArray = [jsonArray objectAtIndex:indexPath.row]; //You got the inner array
        if(innerArray count]>2){
             NSString *yourDesiredString = [innerArray objectAtIndex:2]; //You got the string. Use it now as you wish. It will be 150 for the first cell, 350 for the second and 350 for the third one as well.
         }

    }

}
我没有在这里添加任何异常检查,这是您必须自己做的。我添加了一些基本检查,以防止在出现不相关数据时发生崩溃,您应该对此进行扩展


假设您希望将此字符串设置为每个单元格。如果我误解了你的问题或者你需要问些什么,请留下评论

以便。。。你的代码是什么。。。您尝试过什么吗?您尝试过类似于:array[0][3]?但是,为了回答这个问题,您需要解释数据应该从(JSON?)数据提取到一个实例变量中,因此您需要在实际显示迭代之前解释何时应该分配ivar。一个完整的答案将由OP用“我不能工作”来回答。你需要在索引2处组合所有的字符串吗(第三个索引是2,不是3.0,1,2)?或者您的tableview中的每个单元格都需要这些字符串吗?当您已经有一个tableview运行时,为什么还要再次迭代数组?因为它们需要一次在特定位置的所有值。您也可以在tableview中获得它。TableView正在IndexPath.row上运行,请将其用作索引。从JSON反序列化数据结构中获取相关数据并在将其设置为数据源之前对其进行验证没有什么错。当然,这个答案没有显示任何验证(即内部数组中有多少个元素),就像你的答案一样,一旦收到duff数据,就会严重崩溃。