【发布时间】:2014-05-22 21:32:03
【问题描述】:
大家好,我正在尝试将一些 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
【问题讨论】:
-
给出完整的异常消息和堆栈跟踪 - 它来自哪一行?
-
你是这个意思吗?我在代码下添加了它
-
这并没有告诉我是哪一行。我知道当代码需要一个字符串时你正在使用字典,但你需要知道在哪里 - 哪个字典 - 在你可以修复它之前......
-
我在 All Exceptions 中设置了一个断点,它在主文件中的这一行停止:@autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }
-
我不知道,我唯一拥有的字典是上面的 XMLDictionary (NSDictionary) 和另一个称为 order 的 NSMutableDictionary。