我正在解析来自web服务的数据。在解析了几条记录后,它给出了这个错误。有人请告诉我这个错误背后的原因是什么?
[NSXMLParser length]: unrecognized selector sent to instance 0x6e6d340
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSXMLParser length]: unrecognized selector sent to instance 0x6e6d340'
*** Call stack at first throw:
(
0 CoreFoundation 0x026c4919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x028125de objc_exception_throw + 47
2 CoreFoundation 0x026c642b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02636116 ___forwarding___ + 966
4 CoreFoundation 0x02635cd2 _CF_forwarding_prep_0 + 50
5 Foundation 0x001053e9 -[NSXMLParser parse] + 104
6 SexOffenders 0x00009c30 -[UserProfileVC connectionDidFinishLoading:] + 565
7 Foundation 0x0006e666 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
8 Foundation 0x0006e5bf _NSURLConnectionDidFinishLoading + 133
9 CFNetwork 0x02c569f1 _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 285
10 CFNetwork 0x02d1fc72 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 402
11 CFNetwork 0x02d200ea _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1546
12 CFNetwork 0x02d200ea _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1546
13 CFNetwork 0x02c4bdfe _ZN19URLConnectionClient13processEventsEv + 100
14 CFNetwork 0x02c4bc95 _ZN17MultiplexerSource7performEv + 247
15 CoreFoundation 0x026a5d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x026041dd __CFRunLoopDoSources0 + 333
17 CoreFoundation 0x026037c6 __CFRunLoopRun + 470
18 CoreFoundation 0x02603280 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x026031a1 CFRunLoopRunInMode + 97
20 GraphicsServices 0x02f292c8 GSEventRunModal + 217
21 GraphicsServices 0x02f2938d GSEventRun + 115
22 UIKit 0x002dab58 UIApplicationMain + 1160
23 SexOffenders 0x00002198 main + 102
24 SexOffenders 0x00002129 start + 53
)
terminate called after throwing an instance of 'NSException'
答案 0 :(得分:3)
' - [NSXMLParser length]:无法识别的选择器发送到实例0x6e6d340
这表示您正在调用的函数不是NSXMLParser类的成员函数。
实际上在您的代码中,您正在调用任何无法在NSXMLParser类的对象上调用的方法。
通过调试指针chechk。
答案 1 :(得分:0)
我刚刚遇到同样的问题。对我来说问题是由这行代码引起的:
operation.responseSerializer = [AFXMLParserResponseSerializer serializer];
这序列化responseObject
我将解析器传递给XML但解析器需要一个NSData
对象。简单地摆脱那条线就解决了这个问题。
答案 2 :(得分:0)
我也遇到了类似的问题。
通过更改我的行来修复
self.xmlParser = [[NSXMLParser alloc] initWithData:data];
到
self.xmlParser = (NSXMLParser *)responseObject;
我从这个博客找到了我的解决方案
[AFXMLParserResponseSerializer序列化程序]的这种配置已经返回一个初始化对象,我正在使用已经初始化的解析器再次初始化它,考虑它的数据对象。
按照上面@Hodson的回答,评论以下行并不适合我,因为这是AFTNetworking库的默认配置,所以没有意义。
operation.responseSerializer = [AFXMLParserResponseSerializer serializer];