NSDictionary 长度:无法识别的选择器发送到实例

Mus*_*shi 2 xml parsing ios

大家好,我正在尝试将一些 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);
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Wai*_*ain 5

-[__NSDictionaryI 长度]:发送到实例的无法识别的选择器

此消息告诉您NSDictionary(或者,特别是私有不可变子类__NSDictionaryI)收到了对该length方法的调用,但它没有响应。

'length' 是调用字符串的常用方法,因此可以肯定的是,这正是引发异常的代码所期望的。NSData也有一个length方法,但根据您的代码,这似乎不太可能。

您需要单步执行代码以找到字典的位置,但代码需要一个字符串(或数据)。