替换“\r\n”在 NSMutableString 中,从服务器接收的数据
我通过执行以下代码从服务器获取数据:
- (void) sendGeneral:(NSString *) general{
self.responseData = [NSMutableData data];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:CBURL]];
[request setHTTPMethod:@"POST"];
int i;
i = [general length];
NSLog(@"Length is %i", i);
[request setHTTPBody:[general dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
将其 NSLog 到包含“\r\n”的控制台后得到的数据,正如您从以下数据中看到的那样(仅演示了部分数据)
"numberPhoneFrom":"","FormName":"הרשמה\r\n"},{"CallID":314358,"StartDate":"27/07/2011 19:32","TotalTime":51.0,"numberPhoneFrom":"","FormName":"פרטים כלליים\r\n"},{"CallID":424378,"StartDate":"26/09/2011 18:43","TotalTime":63.6,"numberPhoneFrom":"","FormName":"הרשמה\r\n"},{"CallID":311229,"StartDate":"26/07/2011 13:28","TotalTime":18.6,"numberPhoneFrom":"","FormName":"נסיון\r\n"}
我正在尝试清理“\r\n”与各种命令,但我不能这样做这个代码获取协议中的数据
- (void) GetData: (NSMutableString *)protocol{
[protocol replaceOccurrencesOfString:@"\n" withString:@"" options:0 range:NSMakeRange(0, [protocol length])];
NSLog(@"server data Function%@", protocol);
}
从服务器返回数据在 NSMutableString 中听到
/*****************************************************************/
/* connection finish loading and continue talk */
/*****************************************************************/
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSMutableString* responseString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// NSLog(@"the Server Response was %@", responseString);
[[self delegate] GetData:responseString];
}
有人可以帮忙吗?
Im getting data from a server by executing this code:
- (void) sendGeneral:(NSString *) general{
self.responseData = [NSMutableData data];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:CBURL]];
[request setHTTPMethod:@"POST"];
int i;
i = [general length];
NSLog(@"Length is %i", i);
[request setHTTPBody:[general dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
the data I'm getting after NSLog it to console containing "\r\n" as you can see from the following data (only part of the data to demonstration)
"numberPhoneFrom":"","FormName":"הרשמה\r\n"},{"CallID":314358,"StartDate":"27/07/2011 19:32","TotalTime":51.0,"numberPhoneFrom":"","FormName":"פרטים כלליים\r\n"},{"CallID":424378,"StartDate":"26/09/2011 18:43","TotalTime":63.6,"numberPhoneFrom":"","FormName":"הרשמה\r\n"},{"CallID":311229,"StartDate":"26/07/2011 13:28","TotalTime":18.6,"numberPhoneFrom":"","FormName":"נסיון\r\n"}
Im trying to clean the "\r\n" with all kind of commands but i can't do it this code get the data in the protocol
- (void) GetData: (NSMutableString *)protocol{
[protocol replaceOccurrencesOfString:@"\n" withString:@"" options:0 range:NSMakeRange(0, [protocol length])];
NSLog(@"server data Function%@", protocol);
}
Getting the data back from server in hear in NSMutableString
/*****************************************************************/
/* connection finish loading and continue talk */
/*****************************************************************/
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSMutableString* responseString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// NSLog(@"the Server Response was %@", responseString);
[[self delegate] GetData:responseString];
}
can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大概可以试试这个:
Probably try this:
**在服务器上解决了这个问题,我认为这是最好的办法'服务器更强大,C# 在字符串处理方面非常好,
谢谢。**
**Solved this issue on the server, i think this is the best thing to do' servers are much stronger and C# is very good in string handeling
Thank you.**