OC 数组、字典转换
// 从数组中检索 首字母相同的字符串
// {
// (abs ,abac),
// (b),
// (cdc, cfr)
// }
服务器接收参数
014-04-26 16:31:44.974 ZHRD[7389:60b] city {
hot = (
"U70edU95e8-U5e7fU5ddeU5e02",
"U70edU95e8-U6df1U5733U5e02",
"U70edU95e8-U5317U4eacU5e02",
"U70edU95e8-U4e0aU6d77U5e02"
);
other = (
"C-U957fU6c99U5e02",
"H-U5408U80a5U5e02",
"H-U676dU5ddeU5e02",
"J-U5409U6797U7701",
"K-U6606U660eU5e02",
"L-U4e3dU6c5fU5e02",
"M-U7261U4e39U6c5fU5e02",
"S-U5341U5830U5e02",
"S-U6c55U5934U5e02",
"T-U5510U5c71U5e02",
"T-U5929U6c34U5e02",
"T-U5929U6d25U5e02",
"Y-U5cb3U9633U5e02",
"Y-U70dfU53f0U5e02",
"Z-U6dc4U535aU5e02",
"Z-U91cdU5e86U5e02"
);
}
NSMutableDictionary *dicCity = [data JSONValue];
NSMutableArray *arrHot = [dicCity objectForKey:@"hot"];
NSMutableArray *arrOther = [dicCity objectForKey:@"other"];
NSLog(@"city %@",dicCity);
NSMutableDictionary *dicData = [[NSMutableDictionary alloc]initWithCapacity:1];
for (int i = 0; i < [arrOther count]; i++)
{
NSString *strOne = [arrOther objectAtIndex:i];
NSMutableArray *arrData = [dicData objectForKey:[strOne substringToIndex:1]];
if (!arrData)
{
arrData = [[NSMutableArray alloc]initWithCapacity:1];
[ArrShouzimu addObject:[strOne substringToIndex:1]];
}
[arrData addObject:strOne];
[dicData setObject:arrData forKey:[strOne substringToIndex:1]];
}
// 打印字典 dicData
2014-04-26 16:31:44.978 ZHRD[7389:60b] {
C = (
"C-U957fU6c99U5e02"
);
H = (
"H-U5408U80a5U5e02",
"H-U676dU5ddeU5e02"
);
J = (
"J-U5409U6797U7701"
);
K = (
"K-U6606U660eU5e02"
);
L = (
"L-U4e3dU6c5fU5e02"
);
M = (
"M-U7261U4e39U6c5fU5e02"
);
S = (
"S-U5341U5830U5e02",
"S-U6c55U5934U5e02"
);
T = (
"T-U5510U5c71U5e02",
"T-U5929U6c34U5e02",
"T-U5929U6d25U5e02"
);
Y = (
"Y-U5cb3U9633U5e02",
"Y-U70dfU53f0U5e02"
);
Z = (
"Z-U6dc4U535aU5e02",
"Z-U91cdU5e86U5e02"
);
- 上一篇: OC-042.数组与字符串之间的转换
- 下一篇: IOS中的NSString与NSArray的互转