-2

サーバーからのデータを含む配列があります。サーバーの応答を変更できません。

({
        ObservationMapId = 13;
        "Observation_Type" = Results;
        actionItem = "Tesing action";
        followupdate = "February 14, 2013";
        followupstatus = Open;
        observation = "Testing results for image";
    },
        {
        ObservationMapId = 13;
        "Observation_Type" = Results;
        observation = "Demo observation";
    },
  {     actionItem = "Tesing action";
        followupdate = "February 14, 2013";
        followupstatus = Open;
}
)

次のように、2番目の辞書を3番目の辞書とマージしたい

 ({
            ObservationMapId = 13;
            "Observation_Type" = Results;
            actionItem = "Tesing action";
            followupdate = "February 14, 2013";
            followupstatus = Open;
            observation = "Testing results for image";
        },
            {
            ObservationMapId = 13;
            "Observation_Type" = Results;
            observation = "Demo observation";
            actionItem = "Tesing action";
            followupdate = "February 14, 2013";
            followupstatus = Open;
    }
    )

ヘルプを進める方法がわかりません。前もって感謝します

4

4 に答える 4

1
NSMutableArray *myArray;
[myArray[1] addEntriesFromDictionary:myArray[2]];
[myArray removeObjectAtIndex:2];
于 2013-02-14T11:13:12.983 に答える
0
take the server response in an array-

NSArray *array_Resp; and put server response ({
        ObservationMapId = 13;
        "Observation_Type" = Results;
        actionItem = "Tesing action";
        followupdate = "February 14, 2013";
        followupstatus = Open;
        observation = "Testing results for image";
    },
        {
        ObservationMapId = 13;
        "Observation_Type" = Results;
        observation = "Demo observation";
    },
  {     actionItem = "Tesing action";
        followupdate = "February 14, 2013";
        followupstatus = Open;
}
) 

into this array.

// now take a dictionary

NSMutableDictionary *dictMerged = [NSMutableDictionary new];

dictMerged = [[array_Resp objectAtIndex:1] mutableCopy];

NSDictionary *thirdDict = [array_Resp objectAtIndex:2];

for (id key in [thirdDict allKeys]) {
        [dictMerged setObject:[thirdDict objectForKey:key] forKey:key];
    }

// Now your dictMerged has merged values from 2nd and third dict from array_Resp

NSMutableArray *desiredArray = [NSMutableArray arrayWithObjects:dictMerged, nil];

this desired array will have your required merged dictionaries as 

({
            ObservationMapId = 13;
            "Observation_Type" = Results;
            actionItem = "Tesing action";
            followupdate = "February 14, 2013";
            followupstatus = Open;
            observation = "Testing results for image";
        },
            {
            ObservationMapId = 13;
            "Observation_Type" = Results;
            observation = "Demo observation";
            actionItem = "Tesing action";
            followupdate = "February 14, 2013";
            followupstatus = Open;
    }
    )
于 2013-02-14T11:34:37.100 に答える
0
NSMutableDictionary *dicMerged  = [NSMutableDictionary dictionaryWithDictionary:[YourArray objectAtIndex:1]];
[dicMerged addEntriesFromDictionary:[YourArray objectAtIndex:2]];
 NSMutableArray *artFinal = [NSMutableArray array];
 [artFinal addObject:[YourArray objectAtIndex:0]];
 [artFinal addObject:dicMerged];

print artFinal you will get as you want
于 2013-02-14T11:13:29.783 に答える
0

私があなたを正しく理解しているなら、試してみてください:

[[yourMutableArray objectAtIndex:1] addEntriesFromDictionary:[yourMutableArray objectAtIndex:2]];  
[yourMutableArray removeLastObject];
于 2013-02-14T11:17:30.553 に答える