我正在做 JSON 解析,我想在UITableView
.
为此,我试图将解析后的数据分配给NSMutableDictionary
toNSArray
以显示在表格视图中,但数组返回null
.
这里我的数组返回null
值;
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];
}