NSURLConnection sendSynchronousRequest 数据解析崩溃

发布于 2024-10-19 08:53:31 字数 3586 浏览 2 评论 0原文

我正在使用 sendSynchronousRequest 并从网络服务器接收数据,但当我尝试解析接收到的数据时应用程序崩溃了?

NSError *error;  
NSURLResponse *response;  
NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];  
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];   
NSLog(@"data received from url: %@", data); 
xmlParser = [[NSXMLParser alloc] initWithData: data];   
[xmlParser setDelegate: self];   
[xmlParser setShouldResolveExternalEntities:YES];   
[xmlParser parse];   
[xmlParser release];  

但在 [xmlParser parse]; 之后应用程序崩溃了。我收到以下信息:

2011-03-01 09:36:31.735 MasterApp[228:207] -[NSCFString bytes]: unrecognized selector sent to instance 0x5f6b000  
2011-03-01 09:36:31.738 MasterApp[228:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString bytes]: unrecognized selector sent to instance 0x5f6b000'  
*** Call stack at first throw:  
(  
    0   CoreFoundation                      0x0252eb99 __exceptionPreprocess + 185  
    1   libobjc.A.dylib                     0x0267e40e objc_exception_throw + 47  
    2   CoreFoundation                      0x025306ab -[NSObject(NSObject)   doesNotRecognizeSelector:] + 187  
    3   CoreFoundation                      0x024a02b6 ___forwarding___ + 966  
    4   CoreFoundation                      0x0249fe72 _CF_forwarding_prep_0 + 50  
    5   Foundation                          0x00114afc -[NSXMLParser parse] + 147  
    6   MasterApp                           0x0000c731 -[identifierList getUrl] + 994  
    7   MasterApp                           0x0000c306 -[identifierList   actionSheet:clickedButtonAtIndex:] + 56  
    8   UIKit                               0x0077047d -[UIActionSheet(Private)   _buttonClicked:] + 258  
    9   UIKit                               0x002dc7f8 -[UIApplication   sendAction:to:from:forEvent:] + 119  
    10  UIKit                               0x00367de0 -[UIControl sendAction:to:forEvent:] + 67  
    11  UIKit                               0x0036a262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527  
    12  UIKit                               0x00368e0f -[UIControl touchesEnded:withEvent:] + 458   
    13  UIKit                               0x003003d0 -[UIWindow _sendTouchesForEvent:] + 567  
    14  UIKit                               0x002e1cb4 -[UIApplication sendEvent:] + 447  
    15  UIKit                               0x002e69bf _UIApplicationHandleEvent + 7672  
    16  GraphicsServices                    0x02d8a822 PurpleEventCallback + 1550  
    17  CoreFoundation                      0x0250fff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52  
    18  CoreFoundation                      0x02470807 __CFRunLoopDoSource1 + 215  
    19  CoreFoundation                      0x0246da93 __CFRunLoopRun + 979  
    20  CoreFoundation                      0x0246d350 CFRunLoopRunSpecific + 208  
    21  CoreFoundation                      0x0246d271 CFRunLoopRunInMode + 97  
    22  GraphicsServices                    0x02d8900c GSEventRunModal + 217  
    23  GraphicsServices                    0x02d890d1 GSEventRun + 115  
    24  UIKit                               0x002eaaf2 UIApplicationMain + 1160  
    25  MasterApp                           0x00001dbc main + 102  
    26  MasterApp                           0x00001d4d start + 53  
)  
terminate called after throwing an instance of 'NSException'  
Program received signal:  “SIGABRT”.

提前谢谢您

I am using sendSynchronousRequest and receiving data from a web server but the app is crashing while I am trying to parse the received data?

NSError *error;  
NSURLResponse *response;  
NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];  
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];   
NSLog(@"data received from url: %@", data); 
xmlParser = [[NSXMLParser alloc] initWithData: data];   
[xmlParser setDelegate: self];   
[xmlParser setShouldResolveExternalEntities:YES];   
[xmlParser parse];   
[xmlParser release];  

But after [xmlParser parse]; the app crashes. I am getting the following:

2011-03-01 09:36:31.735 MasterApp[228:207] -[NSCFString bytes]: unrecognized selector sent to instance 0x5f6b000  
2011-03-01 09:36:31.738 MasterApp[228:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString bytes]: unrecognized selector sent to instance 0x5f6b000'  
*** Call stack at first throw:  
(  
    0   CoreFoundation                      0x0252eb99 __exceptionPreprocess + 185  
    1   libobjc.A.dylib                     0x0267e40e objc_exception_throw + 47  
    2   CoreFoundation                      0x025306ab -[NSObject(NSObject)   doesNotRecognizeSelector:] + 187  
    3   CoreFoundation                      0x024a02b6 ___forwarding___ + 966  
    4   CoreFoundation                      0x0249fe72 _CF_forwarding_prep_0 + 50  
    5   Foundation                          0x00114afc -[NSXMLParser parse] + 147  
    6   MasterApp                           0x0000c731 -[identifierList getUrl] + 994  
    7   MasterApp                           0x0000c306 -[identifierList   actionSheet:clickedButtonAtIndex:] + 56  
    8   UIKit                               0x0077047d -[UIActionSheet(Private)   _buttonClicked:] + 258  
    9   UIKit                               0x002dc7f8 -[UIApplication   sendAction:to:from:forEvent:] + 119  
    10  UIKit                               0x00367de0 -[UIControl sendAction:to:forEvent:] + 67  
    11  UIKit                               0x0036a262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527  
    12  UIKit                               0x00368e0f -[UIControl touchesEnded:withEvent:] + 458   
    13  UIKit                               0x003003d0 -[UIWindow _sendTouchesForEvent:] + 567  
    14  UIKit                               0x002e1cb4 -[UIApplication sendEvent:] + 447  
    15  UIKit                               0x002e69bf _UIApplicationHandleEvent + 7672  
    16  GraphicsServices                    0x02d8a822 PurpleEventCallback + 1550  
    17  CoreFoundation                      0x0250fff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52  
    18  CoreFoundation                      0x02470807 __CFRunLoopDoSource1 + 215  
    19  CoreFoundation                      0x0246da93 __CFRunLoopRun + 979  
    20  CoreFoundation                      0x0246d350 CFRunLoopRunSpecific + 208  
    21  CoreFoundation                      0x0246d271 CFRunLoopRunInMode + 97  
    22  GraphicsServices                    0x02d8900c GSEventRunModal + 217  
    23  GraphicsServices                    0x02d890d1 GSEventRun + 115  
    24  UIKit                               0x002eaaf2 UIApplicationMain + 1160  
    25  MasterApp                           0x00001dbc main + 102  
    26  MasterApp                           0x00001d4d start + 53  
)  
terminate called after throwing an instance of 'NSException'  
Program received signal:  “SIGABRT”.

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-10-26 08:53:31

您需要根据收到的数据格式设置解析器。首先,请查看 NSXMLParser 文档NSXMLParserDelegate文档。从这些页面中,您可以找到有用的示例代码,SeismicXMLLazyTableImages

You need to set up the parser based on the format of the data you recieve. To get started, Look at the NSXMLParser documentation and the NSXMLParserDelegate documentation. From those pages you can find helpful sample code, SeismicXML and LazyTableImages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文