如何将NSMutableDictionary中的值赋给NSArray [英] How to assign values from NSMutableDictionary to NSArray
本文介绍了如何将NSMutableDictionary中的值赋给NSArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在进行JSON解析,我想在 UITableView
中显示我的解析数据。
I am doing JSON parsing and I want to show my parsed data in a UITableView
.
为此,我试图将解析后的数据从 NSMutableDictionary
分配到 NSArray
,以在表视图中显示,但数组返回 null
。
For that, I am trying to assign parsed data from NSMutableDictionary
to NSArray
to show in the table view but the array returns null
.
这里我的数组返回 null
value;
Here my array returns null
value;
NSMutableDictionary *tempDict1;
NSArray *arr = [[tempDict1 valueForKey:@"rates"] componentsSeparatedByString:@";"];
代码
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
// NSArray *latestrates = [[responseString JSONValue] objectForKey:@"rates"];
[responseString release];
values = [responseString JSONValue];
array = [[NSMutableArray alloc] init];
array = [values valueForKey:@"rates"];
NSLog(@"array values:--> %@",array);
tempDict1 = (NSMutableDictionary *)array;
arr = [[tempDict1 valueForKey:@"rates"] componentsSeparatedByString:@";"];
NSString *subStar = @"=";
NSMutableArray *arrTitle = [[NSMutableArray alloc] init];
NSMutableArray *arrValues = [[NSMutableArray alloc] init];
[arrTitle removeAllObjects];
[arrValues removeAllObjects];
for (int i=0; i<[arr count]-1; i++)
{
[arrTitle addObject:[[arr objectAtIndex:i] substringToIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:subStar])-1]];
[arrValues addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:subStar])]];
NSLog(@"arrTitle is:--> %@",arrTitle);
}
tempDict1 = (NSMutableDictionary*)[array objectAtIndex:0];
array = [values valueForKey:@"rates"];
NSLog(@"tempDict--%@",tempDict1);
[arr retain];
[tbl_withData reloadData];
}
推荐答案
尝试编辑connectionDidFinishLoading中的第四行
Try editing fourth line in connectionDidFinishLoading to
values = [responseString JSONFragments];
这篇关于如何将NSMutableDictionary中的值赋给NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文