Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 正确解析表视图单元格的JSON_Ios_Json_Uitableview - Fatal编程技术网

Ios 正确解析表视图单元格的JSON

Ios 正确解析表视图单元格的JSON,ios,json,uitableview,Ios,Json,Uitableview,我正在解析API中的JSON,这很好,但每次我选择一行并进入详细视图时,他都会向我显示产品,应该链接到底部显示的产品。我不明白为什么它没有解析特定行的产品id,因为我已经将它设置为解析indexPath.row - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *neuheitenCell = @"

我正在解析API中的JSON,这很好,但每次我选择一行并进入详细视图时,他都会向我显示产品,应该链接到底部显示的产品。我不明白为什么它没有解析特定行的产品id,因为我已经将它设置为解析
indexPath.row

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *neuheitenCell = @"neuheitenCell";
    CJHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:neuheitenCell];

    wareID = [[arrayArtikelWareID objectAtIndex:indexPath.row] objectForKey:@"ware_id"];
    NSLog(@"Waren ID: %@", wareID);

    cell.artikelName.text = [[arrayArtikelName objectAtIndex:indexPath.row] objectForKey:@"name"];
    cell.artikelHersteller.text = [[arrayArtikelHersteller objectAtIndex:indexPath.row] objectForKey:@"lieferant_name"];


    return cell;

}
**编辑:

-(void) parseJSONWithURL: (NSURL *) jsonURL {

    dispatch_async(mainThreadQueue, ^{
        NSError *error = nil;

        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

        NSString *json =[NSString stringWithContentsOfURL:jsonURL encoding:NSUTF8StringEncoding error:&error];

        if (error == nil) {


            NSData *jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];

            dictionaryNewStuff = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
            if (error == nil) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    arrayNeuheiten = [[dictionaryNewStuff valueForKey:@"newstuff"] valueForKey:@"Neuheiten"];
                    arrayArtikelBild = [[dictionaryNewStuff valueForKey:@"newstuff"] valueForKey:@"Neuheiten"];
                    [neuheitenTableView reloadData];
                    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                });
            }

        }
    });

}
JSON可以在我的网站上查看 有人知道如何解决这个问题吗


提前谢谢

您可以尝试使用以下代码吗

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *neuheitenCell = @"neuheitenCell";
    CJHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:neuheitenCell];

    NSDictionary *object = [arrayNeuheiten objectAtIndex:indexPath.row];

    NSString *wareID = [object objectForKey:@"ware_id"];
    NSLog(@"Waren ID: %@", wareID);

    cell.artikelName.text = [object objectForKey:@"name"];
    cell.artikelHersteller.text = [object objectForKey:@"lieferant_name"];


    return cell;
}
为什么需要两个数组来保存数据?我的意思是以下几行“ArrayNewHeiten=[[dictionaryNewStuff valueForKey:@“newstuff”]valueForKey:@“Neuheiten”];arrayArtikelBild=[[dictionaryNewStuff valueForKey:@“newstuff”]valueForKey:@“Neuheiten”];”


另外,您在哪里为arrayArtikelWareID、arrayArtikelName、arrayArtikelHersteller赋值?是否有任何错误,变量为零…有什么问题?没有。我实际上得到了id,但它们的顺序是错误的。我总是得到加载的最后一个单元格的值(最底部的那一个),你能给我们看看json本身吗?你能检查一下数组中的值是否有序吗?这和我在评论中告诉他的是一样的。问题应该在那里你确定吗?确切的问题是什么?尝试NSLog(@“%@”,对象);并查看在此方法“aktionspreis_global”=“0.00”期间检索到哪些对象;《图片报》”;法本=1;gruppe=“M\U00fctzen&H\U00fcte”;“gruppe_id”=27;“gruppe_rubrik”=附件;“gruppe_url”=“Muetzen Huete”;“烈性名称”=德金;“lieferant_url”=Deginter;“menge_bestellbar”=18;mwst=19;name=“Strickm\U00fctze mit Bommel”;“name_url”=“Strickmuetze mit Bommel”;neu=1;位置=89;preis=“89.00”;销售=0;verpackungsservice=ja;“ware_id”=14393;这不一样。它现在已被正确解析,但仍以不正确的顺序打开。正确的顺序是什么?因为现在,单元格0在索引0处有元素没有?也许你可以查一查