-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;
}
)

我想将第二个字典与第三个字典合并如下

 ({
            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

如果我理解正确,请尝试:

[[yourMutableArray objectAtIndex:1] addEntriesFromDictionary:[yourMutableArray objectAtIndex:2]];  
[yourMutableArray removeLastObject];
于 2013-02-14T11:17:30.553 回答
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
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 回答