objective-c里有没有可以实现类似java这种arraylist<hashmap<k,v>>这种的 ,可以给个例子吗?

2024-12-31 13:41:48
推荐回答(1个)
回答1:

json格式:
[{"id":1,"name":"zhangsan:},{"id":2,"name":"lisi"},{"id":3,"name":"wangwu"}]
上述的json格式类似你说的一个数组存放是键值对集合。在objective-c中。数组可以用NSArray or NSMutableArray.键值对用NSDictionary or NSMutableDictionary
---------------------------------------------------------------------------------------------------------------
NSDictionary *dict1=[NSDictionary dictionaryWithObjectAndKey:@"1",@"id",@"zhangsan",@"name",nil];
NSDictionary *dict2=[NSDictionary dictionaryWithObjectAndKey:@"2",@"id",@"lisi",@"name",nil];
NSDictionary *dict1=[NSDictionary dictionaryWithObjectAndKey:@"3",@"id",@"wangwu",@"name",nil];

NSArray *array=[NSArray arrayWithObjects:dict1,dict2,dict3,nil];
NSLog(@"%@",array);