iOS 字典数组排序
- (NSString *)rankAndJiaMiDic:(NSDictionary *)dic{
NSString *str = @"";
NSArray *keyAry = [dic allKeys];
NSArray *sortAry = [keyAry sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
NSMutableArray *valueArray = [@[] mutableCopy];
for (NSString *key in sortAry) {
[valueArray addObject:dic[key]];
}
NSMutableArray *valueary = [[NSMutableArray alloc]init];
for (int i = 0; i < valueArray.count; i++) {
NSString *vaule = [self encodeToPercentEscapeString:StrFormat(@"%@", valueArray[i])];
[valueary addObject:vaule];
}
DLog(@"键值对%@,%@",sortAry,valueary);
NSMutableArray *signArray = [NSMutableArray array];
for (int i = 0; i < sortAry.count; i++) {
NSString *keyValueStr = [NSString stringWithFormat:@"%@=%@",sortAry[i],valueary[i]];
[signArray addObject:keyValueStr];
}
DLog(@"数组排序%@",signArray);
NSString *sign = [signArray componentsJoinedByString:@"&"];
DLog(@"%@数组字符串",sign);
return sign;
}