在ipad的所有朋友即时通讯中,请告诉我为什么我不能发布json var?
NSData* myMutableData = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror];
NSLog(@"slt%d",[myMutableData length]);
json_string=nil;
json_var = [[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
json_var = [json_var stringByReplacingOccurrencesOfString:@">" withString:@">"];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml....... string\">" withString:@""];
json_var = [json_var stringByReplacingOccurrencesOfString:@"</return></ns1:getDatasResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>" withString:@""];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml version="1.0" encoding="UTF-8"?>" withString:@""];
json_var = [json_var stringByReplacingOccurrencesOfString:@"<?xml version="1.0" encoding="windows-1252"?>" withString:@"<?xml version=\"1.0\" encoding=\"windows-1252\"?>"];
NSString *data13=[[NSString alloc] initWithString:json_var];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
IDComp = [IDComp stringByReplacingOccurrencesOfString:@"/" withString:@":"];
NSString *test1 = [IDComp stringByAppendingString:@".xml"];
NSString *test2 = [documentsDirectory stringByAppendingString:@"/"];
NSString *test3 = [test2 stringByAppendingString:test1];
NSString *file2 = [NSString stringWithFormat:test3];
[data13 writeToFile:file2 atomically:YES];
[data13 release];
[json_var release];
答案 0 :(得分:0)
您不需要释放字符串json_var
,因为您为其分配了自动释放的对象(方法stringByReplacingOccurrencesOfString:
会返回自动释放的NSString
)。
如果你不想要下一次应该做的内存泄漏:
[json_var release]
替换
json_var = [[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ];
与
json_var = [[[NSString alloc] initWithData:myMutableData encoding:NSUTF8StringEncoding ]autorelease];