NSDictionary 键中的连字符 [英] hyphen in NSDictionary key
本文介绍了NSDictionary 键中的连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为此工作了几天,但没有运气.我试图从 NSDicitonary 解析一组键/值对,但它似乎对键名中的连字符非常敏感.下面是一个数据示例.如果我尝试使用下面的代码访问带有连字符的任何字段,我会收到以下错误:
I've been working this for a few days now with no luck.. I am trying to parse a collection of key/value pairs from an NSDicitonary but it seems to be very sensitive to a hyphen in the key name. Below is an example of the data.. If I try to access any of the fields with a hyphen using the code below I get the following error:
无法识别的选择器发送到实例
unrecognized selector sent to instance
有什么建议吗?
NSString *param = [[NSString alloc] initWithFormat:@" url-name like %@",url ];
NSPredicate *predicate = [NSPredicate predicateWithFormat:param];
NSArray *results = [aCompanies filteredArrayUsingPredicate:predicate];
<小时>
<company>
<address-one></address-one>
<address-two></address-two>
<city></city>
<country></country>
<id type="integer">11899</id>
<name>Aceara</name>
<phone-number-fax></phone-number-fax>
<phone-number-office></phone-number-office>
<state></state>
<time-zone-id>Central Time (US & Canada)</time-zone-id>
<url-name>ACEARA</url-name>
<uuid>7cc52da5-6783-4c59-9c60-b8fe96f2110c</uuid>
<web-address>WWW.ACEARA.COM</web-address>
<zip></zip>
<can-see-private type="boolean">false</can-see-private>
</company>
推荐答案
用引号将字符串括起来以避免出现问题,例如:
Surround strings with quotes to avoid problems, e.g.:
initWithFormat:@"'url-name' like '%@'"
这篇关于NSDictionary 键中的连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文