开发者

Regarding xml parsing in iphone

I am developing an application in which I am doing XML parsing. I found an error in the [xmlparse parse] method.

Error:

[NSCFString bytes]: unrecognize开发者_Go百科d selector sent to instance 0x3df6310

2010-04-30 00:09:46.302 SPCiphone2[4234:1003] void SendDelegateMessage
    (NSInvocation*): delegate (<CFNotificationCenter 0x3d09670 [0x87dca0]>)
    failed to return after waiting 10 seconds. main run loop mode:
    kCFRunLoopDefaultMode

Code snippet:

responseOfWebResultData = [[NSMutableString alloc]
                           initWithData:responseData
                               encoding:NSUTF8StringEncoding];

NSLog(@"result: %@", responseOfWebResultData);

// starting the XML parsing
if (responseOfWebResultData) {
    @try {
        xmlParser = [[NSXMLParser alloc] initWithData:responseOfWebResultData];
        [xmlParser setDelegate:self];
        [xmlParser setShouldResolveExternalEntities:YES];
        [xmlParser parse];
        [responseOfWebResultData release];
    }
    @catch (NSException *e) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please"
                                                        message:[e reason]
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


You should not be passing in a NSString* into initWithData:. You should do this:

xmlParser = [[NSXMLParser alloc] initWithData:responseData];

The error says that you're sending the message bytes to an instance of NSCFString, which is a NSString*, even though you declared it as a NSMutableString*, because this is a dynamically typed language but the class types are not automatically converted if you try to cast it to something else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜