我想将JSON Object存储到多维数组中。
appDelegate.serviceIdArray = [response1 valueForKey:@"services_id"];
appDelegate.nameArray = [response1 valueForKey:@"services_name"];
appDelegate.rateArray = [response1 valueForKey:@"rate"];
appDelegate.sortDetailArray= [response1 valueForKey:@"short_desc"];
appDelegate.longDetailArray = [response1 valueForKey:@"long_desc"];
appDelegate.imageArray = [response1 valueForKey:@"image"];
提前致谢
答案 0 :(得分:0)
您可以按照以下方式执行此操作:
NSMutableArray *multiArray = [[NSMutableArray alloc] init];
NSArray *serviceIdArray = [response1 valueForKey:@"services_id"];
if( serviceIdArray )
{
[multiArray addObject:serviceIdArray];
}
NSArray *nameArray = [response1 valueForKey:@"services_name"];
if( nameArray )
{
[multiArray addObject:nameArray];
}
NSArray *rateArray = [response1 valueForKey:@"rate"];
if( rateArray )
{
[multiArray addObject:rateArray];
}
NSArray *sortDetailArray= [response1 valueForKey:@"short_desc"];
if( sortDetailArray )
{
[multiArray addObject:sortDetailArray];
}
NSArray *longDetailArray = [response1 valueForKey:@"long_desc"];
if( longDetailArray )
{
[multiArray addObject:longDetailArray];
}
NSArray *imageArray = [response1 valueForKey:@"image"];
if( imageArray )
{
[multiArray addObject:imageArray];
}
...
//do whatever you want with the multi-dimension array
[multiArray release];
答案 1 :(得分:0)
使用SBJSONs。因为你可以使用[对象JSONRepresentation]将json String转换为NSMutableDictionary!
答案 2 :(得分:0)
看起来非常简单,您只需创建NSArray
并使用当前数组调用addObject
。
NSArray *myarray = [[NSArray alloc] initWithObjects:array1,array2,array3,nil];
这将成功