I am doing JSON parsing and I want to show my parsed data in a UITableView
.
For that, I am trying to assign parsed data from NSMutableDictionary
to NSArray
to show in the table view but the array returns null
.
Here my array returns null
value;
NSMutableDictionary *tempDict1;
NSArray *arr = [[tempDict1 valueForKey:@"rates"] componentsSeparatedByString:@";"];
code
- (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];
}
Try editing fourth line in connectionDidFinishLoading to
Now you can get it according to data format.
EDIT
I think you also dont know how to get a
webResponse
.So here is a way to get
webResponse
- First setXML
delegate in yourViewController.h
class and declare aNSMutableData
globalyNow synthesized this
responseData
in yourViewController.m
classNow you can send
request
on server inviewDidLoad:
method its up to you in which method you want to send it.