我正试图利用个案敏感个案来回应JSON对NSDdictionary的反应,因为有时我的反应键类型各不相同,有些是骆驼,有些是小个案,有些是其他混合组合。 是否有功能可以用来检查本案的敏感个案?
谢谢
我正试图利用个案敏感个案来回应JSON对NSDdictionary的反应,因为有时我的反应键类型各不相同,有些是骆驼,有些是小个案,有些是其他混合组合。 是否有功能可以用来检查本案的敏感个案?
谢谢
最近我分享了两个可能适合您需要的类别。 它们提供不区分大小写操作( 以 < code> NSdictionary 和 < code> NS Muttabledictionary 方法命名), 同时保留原插入的密钥 。
试试看:
最好的办法是确定关键,使国家统计词典要么是所有小写字母,要么是所有大写字母;
例如,让我们假设我有一个字符串的 NASARAR 。 我可以在使用它之前获得密钥Name, 并使用小写String 或大写String 转换它 。
NSString *itemName = @"lastName";
itemName = [itemName lowercaseString];
这将将字符串更改为上名, 或者如果我使用大写 String, 它将会是 LastNAME
或者您也可以在加入字典时更改密钥名 :
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:objectToAdd forKey:[key uppercaseString]];
- (NSString *)lowercaseString
它是一种默认的NSString方法, 只要在添加或读取 NSM MudableDigital 时做 [关键小写String] 。
在我的情况下,我不需要所有的词典方法或属性。 我只是需要对案例敏感的下标访问。 我做了一个自定义类 ( non a super sulve sableDigitary), 并运用了允许下标访问的方法, 使这些案例变得不敏感 :
- (id) objectForKeyedSubscript: (NSString *) key {
NSMutableDictionary *theData = self->data;
return theData[[key lowercaseString]];
}
- (void) setObject: (id) newValue forKeyedSubscript: (NSString *) key {
NSMutableDictionary *theData = self->data;
theData[[key lowercaseString]] = newValue;
}
See also: http://clang.llvm.org/docs/ObjectiveCLiterals.html
另一种方法是使用NSString的子类来比较键子, 从而忽略案例( 或diacritics etc.) 。
其优点在于它将原始字符串保留在字典中。 在其他任何您想要比对其他语言特定规则的地方, 它也有用 。
但是,这个方法要求您首先将 JSON 字典中的密钥转换为这种特定字符串类型的实例, 然后将其放回字典中。 这意味着如果您从 JSON 字符串中创建字典, 这样做并不容易。
我做了这样一个子类,见https://gist.github.com/tempelmann/0721dc3b7b39b1eeb7095ebaf316
另见我的。
For a basic app with nonconsumable in-app purchases, has anyone figured out best practices for using SKPaymentQueue s restoreCompletedTransactions? Observations I know it s recommended to always ...
I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...
I have a UITextField that is a subview of a UITableViewCell. When my view loads, I want the text field to become first responder. I have a pointer to the text field in the table cell, so to do this I ...
I ve been working on adding in-app purchases and was able to create and test in-app purchases using Store Kit (yay!). During testing, I exercised my app in a way which caused the app to crash mid ...
In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...
Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...
I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...
Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...