-(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服务的响应。NSString的最大长度是多少?替代NSString - iPhone
但有时,当响应可能是一个巨大的大小。在这种情况下,连接已经收到超过50000字节的数据。 &当我NSlogs NSString - 它打印(空)。
在这种情况下,我无法将网络服务响应存储到文件中。
这应该是什么解决方案? 是否有任何替代方式的NSString? (为此目的)
在此先感谢。
萨加尔。
您可以创建一个带有字节,可变或不可变的文件。请参阅http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/doc/uid/20000172-CIAEAHFJ以获取使用的一种方法。 – 2009-10-27 18:22:11
您可以生成“”的字节等价物,并在可变数据对象中查找关联的字节范围。然后,您可以用NULL替换这些字节:http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/Reference/NSMutableData.html#//apple_ref/doc/uid/20000173 -BGBBIABA –
2009-10-27 18:43:50
先生,但是,在这里我很困惑。无论Web服务如何回应,我都想删除问题中给出的部分内容。我的问题是“是否可以使用nsstring?” “更可取的是可变数据?” “如何用nsmutable数据替换它?” – 2009-10-27 18:52:03