-3

以下のjsonを取得しようとしていますが、すべてのタグが動的で固定されていません。

{
Level1: {
row1: {
1: "on",
2: "off",
3: "off",
4: "on",
5: "on",
6: "on",
7: "on",
8: "on",
9: "on",
10: "on",
11: "on",
12: "on",
13: "on",
14: "on",
15: "on",
16: "on",
17: "on",
18: "on",
19: "on",
20: "on",
attr: {
total: "20",
type: "Gold"
}
},
row10: {
1: "on",
2: "on",
3: "on",
4: "on",
5: "on",
6: "on",
7: "on",
8: "on",
9: "on",
10: "on",
11: "on",
12: "on",
13: "on",
14: "on",
15: "on",
16: "on",
17: "on",
18: "on",
19: "on",
20: "on",
attr: {
total: "20",
type: "Bronze"
}
}
},
Level3: {
row1: {
1: "on",
2: "on",
3: "on",
4: "on",
5: "on",
6: "on",
7: "on",
8: "on",
9: "on",
10: "on",
11: "on",
12: "on",
13: "on",
14: "on",
15: "on",
16: "on",
17: "on",
18: "on",
19: "on",
20: "on",
attr: {
total: "20",
type: "Gold"
}
},
row5: {
1: "on",
2: "on",
3: "on",
4: "on",
5: "on",
6: "on",
7: "on",
8: "on",
9: "on",
10: "on",
11: "on",
12: "on",
13: "on",
14: "on",
15: "on",
16: "on",
17: "on",
18: "on",
19: "on",
20: "on",
attr: {
total: "20",
type: "Bronze"
}
}
}
}

これは私がこれまでに試したことです。

NSString *level;
for(NSString *key in [[self.mGetDataDict allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)])
{
    NSLog(@"Accessing .... %@",key);
    level = key; 

    for(NSString *rowKey in self.mGetDataDict[key])
    {
        [arrayLevels addObject:level];

        NSLog(@"%@",rowKey);
        [arrRows addObject:rowKey];
        for(NSString *valueKey in self.mGetDataDict[key][rowKey])
        {
            // NSLog(@"%@ -> %@",valueKey,self.mGetDataDict[key][rowKey][valueKey]);
            if([valueKey isEqualToString:@"attr"])
            {
                dictRow = self.mGetDataDict[key][rowKey][valueKey];
            }
            else{
                 //dictRow = self.mGetDataDict[key][rowKey][valueKey];
                [arrSeatsStatus addObject:self.mGetDataDict[key][rowKey][valueKey]];
            }
        }
        NSLog(@"--------ROW OVER------------%@\n", dictRow);
        [arrSeats addObject:[dictRow valueForKey:@"total"]];
         NSString *strTypes = [NSString stringWithFormat:@"%@ %@", [arrayLevels objectAtIndex:i], [dictRow valueForKey:@"type"]];
        [arrTypes addObject:strTypes];

            NSMutableArray *array = [NSMutableArray array];
            array = [arrSeatsStatus copy];
            [seatsDict setObject:array forKey:[NSString stringWithFormat:@"%d",i]];
            i++;
            [arrSeatsStatus removeAllObjects];

        NSLog(@"--------seats dict------------%@\n", seatsDict);

        NSLog(@"--------seats in row------------%@\n", arrSeats);
       // NSLog(@"--------seats status------------%@\n", arrStatus);
        NSString *row = [NSString stringWithFormat:@"%@",[arrSeats objectAtIndex:0]];
        rows = [row integerValue];
    }
    NSString *num = [arrSeats valueForKeyPath: @"@sum.self"];
    tot = [num integerValue];
    [arrTot addObject:[NSString stringWithFormat:@"%d",tot]];
    tot = 0;
    //[arrSeats removeAllObjects];
    NSLog(@"--------ROW OVER tot seats------------%@\n", arrTot);
    NSLog(@"--------------------seats:%@\n", num);
    NSLog(@"--------------------\n");
}

問題は、データがフェッチされたときに、JSON からのデータとして正しくないことです。たとえば、上記のコードを実行すると、最初に level2 がフェッチされ、次に row2 がフェッチされ、さらに、上記のように順序どおりではありません。私がそれを明確にしたことを願っています。上記をご案内します。前もって感謝します。

4

2 に答える 2