gpt4 book ai didi

ios - NSDictionary 长度 :unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-12-01 18:14:54 25 4
gpt4 key购买 nike

大家好,我正在尝试将一些 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

最佳答案

-[__NSDictionaryI length]: unrecognized selector sent to instance

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

'length' 是调用字符串的常用方法,因此可以相当安全地打赌,这就是抛出异常的代码所期望的。 NSData 也有一个 length 方法,但根据您的代码,这似乎不太可能。

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

关于ios - NSDictionary 长度 :unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22966650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com