标签:
在解析json的时候,经常json的变量名都是蛇行式(下划线)命名法来命名的,所以写了一个类方法来转换。
+ (NSString *)convertToCamelCaseFromSnakeCase:(NSString *)key { NSMutableString *str = [NSMutableString stringWithString:key]; while ([str containsString:@"_"]) { NSRange range = [str rangeOfString:@"_"]; if (range.location + 1 < [str length]) { char c = [str characterAtIndex:range.location+1]; [str replaceCharactersInRange:NSMakeRange(range.location, range.length+1) withString:[[NSString stringWithFormat:@"%c",c] uppercaseString]]; } } return str; }
标签:
原文地址:http://www.cnblogs.com/ypli/p/4439342.html