我有两个 NSMutableDictionaries
//ServiceResponse 是 NSMutableDictionary
NSMutableDictionary *LocalDict=[[NSMutableDictionary alloc]initWithDictionary:serviceResponse];
当我在 LocalDict 中进行一些更改时,ServiceResponse 也在发生变化。我认为 LocalDict 正在参考 serviceResponse。我做了很多更改但无法解决这个问题。请告诉我如何解决这个问题。为什么 serviceResponse 会发生变化。
if ([[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"]!=[NSNull null]) {
if ([[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"]count]>0) {
if ([[[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]!=[NSNull null]) {
NSMutableDictionary *LocalDict=[[NSMutableDictionary alloc]initWithDictionary:serviceResponse];
for (int j=0; j< [[[[[[LocalDict valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"] count] ;j++) {
for (int i=1; i<=5; i++) {
NSURL * imageURL = [NSURL URLWithString:[[[[[[[LocalDict valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]objectAtIndex:j] valueForKey:[NSString stringWithFormat:@"ThumbNailImage%d",i]]];
if (![[imageURL absoluteString]isEqualToString:@""]) {
NSData * imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%d.png",[[[[[[[LocalDict valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]objectAtIndex:j] valueForKey:@"ProductID"],i]];
[imageData writeToFile:savedImagePath atomically:NO];
[[[[[[[LocalDict valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]objectAtIndex:j]setValue:savedImagePath forKey:[NSString stringWithFormat:@"ThumbNailImage%d",i]];
}
}
}
[dbManager insertProductsDetails:[[[[[LocalDict valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Products"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]];
}
}
}
/*
* Favourites details
*/
if ([[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Favourite"]!=[NSNull null]) {
if ([[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Favourite"]count]>0) {
if ([[[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Favourite"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]!=[NSNull null]) {
[dbManager insertFavouritesDetails:[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"Favourite"]];
}
}
}
/*
* Rep Details
*/
if ([[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"RepDetails"]!=[NSNull null]) {
if ([[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"RepDetails"]count]>0) {
if ([[[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"RepDetails"] objectAtIndex:0]valueForKey:@"OutputProductsDetails"]!=[NSNull null]) {
[dbManager insertRepUserDetails:[[[serviceResponse valueForKey:@"GetAllDetailsResult"]objectAtIndex:0]valueForKey:@"RepDetails"]];
}
}
}