-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *theXML = [[NSString alloc] initWithBytes: [myWebData mutableBytes] length:[myWebData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);
[self actualString:theXML
extractMyData:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><GetCategoryResponse xmlns=\"http://tempuri.org/\"><GetCategoryResult>"
endingString:@"</GetCategoryResult></GetCategoryResponse></soap:Body></soap:Envelope>"
emptyString:@"<Prop_Category />"];
[theXML writeToFile:[self GetMyFilePath] atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
[theXML release];
}
-(NSArray*)actualString:(NSString*)theXML extractMyData:(NSString*)prefixString endingString:(NSString*)suffixString emptyString:(NSString*)noDataFromXMLString{
// now here I want to extract data from string
// from theXML
}
-(NSString*)GetMyFilePath{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentDirectory=[paths objectAtIndex:0];
NSString *pathToUserCopyofplist=[documentDirectory stringByAppendingPathComponent:@"myWebServiceData.plist"];
NSLog(@"%@",pathToUserCopyofplist);
return pathToUserCopyofplist;
}
我想在plist文件中保存为asp.net Web服务的响应。
但有时,当响应可能是巨大的。在这种情况下,连接已接收超过50,000字节的数据。当我NSlogs NSString - 它打印(null)。
在这种情况下,我无法将Web服务响应存储到文件中。
应该解决这个问题?有没有NSString的替代方式? (为此目的)
答案 0 :(得分:4)
如果您想存储某些内容,则您已经拥有字节:[myWebData mutableBytes]
答案 1 :(得分:1)
这是一款移动设备,请记住。内存非常有限,当你说你可能想分配超过500000字节时,它会为我抛出一个红旗。对于这种设计,这将是一个问题。
如果文件大小超过 n ,请考虑使用流式或块式算法。也许您的Web服务可以将响应分解为合理(和已知的最大)大小和设备的部分,并在接收文件时将它们写入文件中?