NSXmlParser 有时无法正确解析 xml
当我调用 API 并解析响应 xml 时,有时会出现此错误..
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSXMLParser stringByAppendingString:]: unrecognized selector sent to instance 0x6a22080'
*** Call stack at first throw:
(
0 CoreFoundation 0x014c7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012bc5c2 objc_exception_throw + 47
2 CoreFoundation 0x014c96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01439366 ___forwarding___ + 966
4 CoreFoundation 0x01438f22 _CF_forwarding_prep_0 + 50
5 CityDeal24 0x0002520e -[CategoryXmlHandler parser:foundCharacters:] + 112
6 Foundation 0x001e8dd4 _characters + 235
7 libxml2.2.dylib 0x018371fb xmlParseCharData + 287
8 libxml2.2.dylib 0x01845a6f xmlParseChunk + 3730
9 Foundation 0x001e921a -[NSXMLParser parse] + 321
10 CityDeal24 0x00025030 -[CategoryXmlHandler parseXML:apiUrl:] + 444
11 CityDeal24 0x00004ac6 -[DagenDealsViewController downloadCategories] + 227
12 CityDeal24 0x00006708 -[DagenDealsViewController doInBackgroundWhenViewWillLoad] + 114
13 Foundation 0x0011ad4c -[NSThread main] + 81
14 Foundation 0x0011acd8 __NSThread__main__ + 1387
15 libSystem.B.dylib 0x9821c85d _pthread_start + 345
16 libSystem.B.dylib 0x9821c6e2 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
when I call API and parse response xml, sometime I got this error ..
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSXMLParser stringByAppendingString:]: unrecognized selector sent to instance 0x6a22080'
*** Call stack at first throw:
(
0 CoreFoundation 0x014c7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012bc5c2 objc_exception_throw + 47
2 CoreFoundation 0x014c96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01439366 ___forwarding___ + 966
4 CoreFoundation 0x01438f22 _CF_forwarding_prep_0 + 50
5 CityDeal24 0x0002520e -[CategoryXmlHandler parser:foundCharacters:] + 112
6 Foundation 0x001e8dd4 _characters + 235
7 libxml2.2.dylib 0x018371fb xmlParseCharData + 287
8 libxml2.2.dylib 0x01845a6f xmlParseChunk + 3730
9 Foundation 0x001e921a -[NSXMLParser parse] + 321
10 CityDeal24 0x00025030 -[CategoryXmlHandler parseXML:apiUrl:] + 444
11 CityDeal24 0x00004ac6 -[DagenDealsViewController downloadCategories] + 227
12 CityDeal24 0x00006708 -[DagenDealsViewController doInBackgroundWhenViewWillLoad] + 114
13 Foundation 0x0011ad4c -[NSThread main] + 81
14 Foundation 0x0011acd8 __NSThread__main__ + 1387
15 libSystem.B.dylib 0x9821c85d _pthread_start + 345
16 libSystem.B.dylib 0x9821c6e2 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请检查所有字符串数据是否有值。
如果某个字符串值为零,那么你会得到这样的错误。因此,还包括空值的条件。
Please check that, all the string data have values or not.
If some string value will be nil then you will get such error. So, include the condition for null value also.
正如错误所示,您正在
NSXMLParser
上调用stringByAppendingString:
。在您的项目中搜索stringByAppendingString:
并确保您在字符串上调用它。As the error says, you are calling
stringByAppendingString:
on anNSXMLParser
. Search your project forstringByAppendingString:
and make sure you are calling it on a string.看起来,您正在对
NSXMLParser
对象调用stringByAppendingString
方法。编辑:
我假设您已将 .h 中的
currentElement
声明为NSMutableArray
并在 中分配 init 函数如下所示。Look like, you are calling
stringByAppendingString
method on the object ofNSXMLParser
.EDITED:
I assume, you have declared
currentElement
in your .h asNSMutableArray
and alloced that in init function like below.