我对此代码有错误
NSString *theURL = @"http://www.w3schools.com/xml/cd_catalog.xml";
NSData *theData=[NSData dataWithContentsOfFile:[NSURL URLWithString:theURL]];
NSDictionary *theDic=[XMLReader dictionaryForXMLData:theData error:nil];错误是
2013-02-10 00:39:05.113 MyXml[4139:c07] -[NSURL getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x7139670
2013-02-10 00:39:05.115 MyXml[4139:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSURL getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x7139670'
*** First throw call stack:
(0x1c96012 0x10d3e7e 0x1d214bd 0x1c85bbc 0x1c8594e 0xad3ee4 0xad3e92 0xad3de2 0xaf2336 0x2bb8 0x15157 0x15747 0x1694b 0x27cb5 0x28beb 0x1a698 0x1bf1df9 0x1bf1ad0 0x1c0bbf5 0x1c0b962 0x1c3cbb6 0x1c3bf44 0x1c3be1b 0x1617a 0x17ffc 0x295d 0x2885)
libc++abi.dylib: terminate called throwing an exception发布于 2013-02-10 14:01:35
它会给出错误,因为你是在dataWithContentsOfFile的帮助下用文件初始化NSData,但实际上你给了初始化它的NSData的URL。正因为如此,你的代码间接调用了NSURL上文件getFileSystemRepresentation:maxLength:的方法,这就是为什么它给出了错误未知选择器的原因。
使用此dataWithContentsOfURL而不是dataWithContentsOfFile
NSString *theURL = @"http://www.w3schools.com/xml/cd_catalog.xml";
NSData *theData=[NSData dataWithContentsOfURL:[NSURL URLWithString:theURL]];https://stackoverflow.com/questions/14795092
复制相似问题