0

メソッドにアクセスする辞書コンテンツの配列を実装しましたが、1 つのコンテンツにしかアクセスできません。これについて助けてください

ここに私のデータファイルがあります

<__NSArrayM 0x8b7a350>(
{
    clkDate = "Wednesday, April 11, 2012";
    resData =     (
                {
            data = 10;
            independentItem = 0;
            module = 6;
            newDate = "11-4-2012";
            newTime = "13:31";
            seqCounter = 101;
            sequence = 10007;
            session = 101;
            timeframe = Breakfast;
            timestamp = "2012-04-11 08:01:27 +0000";
            title = "Glucose reading : Low";
            type = L;
        },
                {
            data =             {
                hours = 0;
                minutes = 0;
                which = "Walking:(null)";
            };
            independentItem = 1;
            module = 13;
            seqCounter = 101;
            sequence = 10009;
            session = 101;
            timestamp = "2012-04-12 08:01:40 +0000";
            title = "Low Cause: Increased Exercise";
        }
    );
    seqCounter = 101;
},
{
    clkDate = "Thursday, April 12, 2012";
    resData =     (
                {
            data = 200;
            independentItem = 0;
            module = 6;
            newDate = "12-4-2012";
            newTime = "13:31";
            seqCounter = 102;
            sequence = 10017;
            session = 101;
            timeframe = Breakfast;
            timestamp = "2012-04-12 08:01:46 +0000";
            title = "Glucose reading : High";
            type = H;
        },
                {
            data =             {
                hours = 0;
                minutes = 0;
                which = "Other Light:Kkkkk";
            };
            independentItem = 1;
            module = 26;
            seqCounter = 102;
            sequence = 10022;
            session = 101;
            timestamp = "2012-04-11 18:30:00 +0000";
            title = "High Cause: Decreased Exercise";
        }
    );
    seqCounter = 102;
},
{
    clkDate = "Thursday, April 12, 2012";
    clkIndependentItem = 1;
    resData =     (
                {
            data =             {
                bathing = 1;
                driving = 1;
                grocery = 1;
                meal = 1;
            };
            independentItem = 1;
            module = 31;
            seqCounter = 103;
            sequence = 10035;
            session = 101;
            timestamp = "2012-04-12 08:02:32 +0000";
            title = "High Cause: Decreased activity";
        }
    );
    seqCounter = 103;
}
)

上記のデータ ファイルでは、「independentItem = 1」関連アイテムにアクセスする必要があります

私が試したソースコードは

for (int i = 0; i < [self.gluClkDetailArray count]; i++) 
        {
            NSMutableDictionary *mDict = [self.gluClkDetailArray objectAtIndex:i];
            {
                NSMutableArray *mResData = [mDict objectForKey:@"resData"];
                NSDate *mTimestamp = [[mResData objectAtIndex:0] objectForKey:@"timestamp"];

                NSDateFormatter *mFormatter = [[NSDateFormatter alloc] init];
                [mFormatter setDateStyle:NSDateFormatterFullStyle];

                NSString *mClkDate = [mFormatter stringFromDate:mTimestamp];
                [mDict setValue:mClkDate forKey:@"clkDate"];

                NSString *mIndItem = [[mResData objectAtIndex:0] objectForKey:@"independentItem"];
                if (mIndItem.intValue == 1) 
                {
                    [mDict setValue:mIndItem forKey:@"clkIndependentItem"];
                    [mIndpendentArray addObject:mDict];
                }
                [gluClkResultArray addObject:mDict]; 

        }

i の代わりに mResData objectAtIndex:0 を配置すると、アプリがクラッシュしました。シーケンスカウンターに基づいて辞書値の配列を保存しました

前もって感謝します

4

1 に答える 1

0

変化する

NSString *mIndItem = [[mResData objectAtIndex:0] objectForKey:@"independentItem"];

それに:

NSString *mIndItem = [[mResData objectAtIndex:1] objectForKey:@"independentItem"];

独立したアイテムは、0ではなくインデックス1にあるディクショナリにあります。

それが役に立てば幸い

于 2012-04-13T08:25:49.477 に答える