大家好我正在尝试将一些XML数据解析到我的tableview并获得此失败:无法识别的选择器发送到实例。我有一个XMLReader类,用于将XML转换为我从此站点获得的NSDictionary: http://ios.biomsoft.com/2011/09/11/simple-xml-to-nsdictionary-converter/ 我怎样才能让应用程序工作?
- (void)viewDidLoad
{
[super viewDidLoad];
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"yxz"];
//get content of url
NSURLRequest* request=[NSURLRequest requestWithURL:url];
NSURLResponse*response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error) {
NSLog(@"ERROR: %@",error);
}
// NSLog(@"data: = %@",data);
NSString* dataAsString =[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
//NSLog(@"dataAsString= %@",dataAsString);
//parse content
feeds = [[NSMutableArray alloc]init];
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:dataAsString error:&error];
if(xmlDictionary==nil){NSLog(@"ERROR: Dictionary is NULL");}
else{
if ([xmlDictionary objectForKey:@"OrderList"]==nil) {NSLog(@"OrderList not found");}
else{
if([[xmlDictionary objectForKey:@"OrderList"]objectForKey:@"Order"]==nil) {NSLog(@"No Orders");}
else
{
feeds = [[xmlDictionary objectForKey:@"OrderList"]objectForKey:@"Order"];
}
}
}
NSLog(@"XMLDictionary: %@",xmlDictionary);
}
XML示例(删除了不重要的值)
<?xml version="1.0" encoding="ISO-8859-1"?>
<OrderList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xyz/schema/OrderListSchema.xsd">
<Order>
<ID></ID>
<Name></Name>
<Payment></Payment>
<Marge></Marge>
<CountryISO2></CountryISO2>
<Status ></Status>
</Order>
2014-04-09 16:42:16.786 djisjdk[714:60b] -[__NSDictionaryI length]: unrecognized
selector sent to instance 0x8c46d10
(lldb) bt
* thread #1: tid = 0x287a, 0x015718b9 libobjc.A.dylib`objc_exception_throw, queue =
'com.apple.main-thread', stop reason = breakpoint 1.3
frame #0: 0x015718b9 libobjc.A.dylib`objc_exception_throw
答案 0 :(得分:4)
- [__ NSDictionaryI长度]:无法识别 选择器发送到实例
此消息告诉您NSDictionary
(或者,具体而言,私有不可变子类__NSDictionaryI
)接收到length
方法的调用,但它没有响应。
&#39;长度&#39;是一个调用字符串的常用方法,所以这是一个相当安全的赌注,这就是抛出异常的代码所期望的。 NSData
也有length
方法,但这似乎不太可能基于您的代码。
您需要单步执行代码以查找字典的位置,但代码需要字符串(或数据)。