JSON格式代碼看起來是這樣的:如何可以打印陣列JSON值插入的UITableView在iphone
array = [values valueForKey:@"rates"];
:
{
"rates": {
"amc": "201",
"hyd": "500.50",
"guj": "200.10",
"afgd": "400"
}
}
解析JSON值以上代碼陣列返回後哪個陣列返回
{
amc = "201";
hyd = "500.50";
guj = "200.10";
afgd = "400";
...........etc
}
但我想打印在UITableView
看看amc:201
我該怎麼做?
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
values = [responseString JSONValue];
array = [[NSMutableArray alloc] init];
NSMutableArray *arrTitle = [[NSMutableArray alloc] init];
NSMutableArray *arrValues = [[NSMutableArray alloc] init];
array =[values valueForKey:@"rates"];
NSLog(@"array values:--> %@",array);
// NSLog(@"values:--> %@",values);
// NSLog(@"Particular values:--> %@",[[values valueForKey:@"rates"] valueForKey:@"AED"]);
tempDict1 = (NSMutableDictionary *)array;
NSArray *arr;// =[[NSArray alloc]init];
arr = [[tempDict1 valueForKey:@"rates"] componentsSeparatedByString:@";"];
NSLog(@"arr-->%@",arr);
NSString *subStar = @"=";
[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 objectForKey:@"AED"]);
[array retain];
[tbl_withData reloadData];
}
什麼是'dz'?它是如何聲明的? –
你甚至嘗試了谷歌搜索嗎?尋找一個json解析器或自己做。提示:這是一個'NSDictionary'。 – Novarg
你已經完成了dz一個,但問題是如何使用forloop從nsdictionary獲取值到nsarray打印uitableview ????? – areddy