首先,您需要阅读一些 iOS 编程基础知识。和,
NSMutableDictionary *temp = [[NSMutableDictionary alloc]init];
NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
temp = [responseString JSONValue]; //----> this line is wrong
因为,temp
指针指向新创建的NSMutableDictionary
对象,您正在将它重新分配给方法返回的另一个对象JSONValue
,即autorelease
对象,并且您不拥有它,因此不能release
。实现您想要的一些更好的方法是:
NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSMutableDictionary *temp = [responseString JSONValue];
NSLog(@"webdata is %@",temp);
NSLog(@"inside usersignup success");
[[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp];
//NO RELEASING the AUTORELEASE OBJECT!!!!
或者:
NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSMutableDictionary *temp = [[NSMutableDictionary alloc]initWithDictionary:[responseString JSONValue]];
NSLog(@"webdata is %@",temp);
NSLog(@"inside usersignup success");
[[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp];
[temp release];
或者:
NSMutableDictionary *temp = [[NSMutableDictionary alloc]init];
NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
[temp addEntriesFromDictionary:[responseString JSONValue]];
NSLog(@"webdata is %@",temp);
NSLog(@"inside usersignup success");
[[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp];
[temp release];
在最后两种情况下,我正在考虑该JSONValue
方法返回NSDictionary
。祝你好运!