我有兩個NSMutableDictionaries分配一個NSMutableDictiory到另一個的NSMutableDictionary給概率
// ServiceResponse是的NSMutableDictionary
NSMutableDictionary *LocalDict=[[NSMutableDictionary alloc]initWithDictionary:serviceResponse];
時,我在LocalDict一些變化則ServiceResponse也changing.i認爲LocalDict走的是serviceResponse.i的參考做了許多改變,但無法解決這個問題。請告訴我如何解決這個問題。爲什麼發生在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"]];
}
}
}
嘗試針對localDictionary中的鍵設置Service Response字典。 – Ashim
什麼是可怕的數據結構...因爲localDictionary不是深層複製的serviceResponse,你應該讓你自己的深拷貝 – adali
,但我需要與服務響應dictionary.Is任何其他方式沒有改變格式我可以做這個 ? – garry007