Iphone NSXmlParser有时无法正确解析xml

Iphone NSXmlParser有时无法正确解析xml,iphone,nsxmlparser,Iphone,Nsxmlparser,当我调用API并解析响应xml时,有时会出现以下错误 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSXMLParser stringByAppendingString:]: unrecognized selector sent to instance 0x6a22080' *** Call stack at first throw: ( 0 CoreFo

当我调用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'

请检查所有字符串数据是否有值。
如果某个字符串值为零,则会出现这样的错误。因此,也包括null值的条件。

正如错误所说,您正在NSXMLParser上调用stringByAppendingString:。在项目中搜索stringByAppendingString:并确保在字符串上调用它。

看起来,您在NSXMLParser的对象上调用stringByAppendingString方法

编辑:

我假设,您已经在.h中将currentElement声明为NSMutableArray,并在init函数中分配了它,如下所示

  currentElement =  [NSMutableArray alloc] initWithCapacity:10];

显示你的代码,在那里你得到崩溃..不,我调用它是为了字符串值我通过解析器的foundCharacters方法得到的…@Sabir Ali:你能找到你调用functrion stringByAppendingString的代码吗。-voidparser:NSXMLParser*解析器foundCharacters:NSString*string{currentElement=[currentElement stringByAppendingString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];NSLog@%@,string;}currentElement是NSString变量,因此m将传入字符追加到其中。@Sabir Ali:您不能追加到NSString对象中,因为它是不可变的字符串,无法更改。
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
     [currentElement appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
     NSLog(@"%@",string);
  }