开发者

NSXmlParser not parsing xml correctly sometime

开发者 https://www.devze.com 2023-03-10 21:51 出处:网络
when I call API and parse response xml, sometime I got this error .. Terminating app due to uncaught exception \'NSInvalidArgumentException\', reason: \'-[NSXMLParser stringByAppendingString:]: unrec

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 d开发者_Python百科ownloadCategories] + 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'


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.


As the error says, you are calling stringByAppendingString: on an NSXMLParser. Search your project for stringByAppendingString: and make sure you are calling it on a string.


Look like, you are calling stringByAppendingString method on the object of NSXMLParser.

EDITED:

I assume, you have declared currentElement in your .h as NSMutableArray and alloced that in init function like below.

  currentElement =  [NSMutableArray alloc] initWithCapacity:10];

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
     [currentElement appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
     NSLog(@"%@",string);
  } 
0

精彩评论

暂无评论...
验证码 换一张
取 消