【发布时间】:2016-08-04 12:21:40
【问题描述】:
有类似的问题,但我找不到任何适合我的解决方案。
我从链接中获得了所有数据为JSON,但我无法理解如何在 uitableview 上显示这些数据。它会显示在主页上。它有title、info。现在我只需要在主页上显示title 和info。
NSURL *url = [NSURL URLWithString:@"http://mantis.vu.edu.pk/fundme/public/api/v1/ideas"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *jsonOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:urlRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSDictionary *responseDict = (NSDictionary *)JSON;
ideasArrayList = [[NSMutableArray alloc] init];
for (NSDictionary *innerObject in [responseDict objectForKey:@"data"])
{
[ideasArrayList addObject:innerObject];
if (ideasArrayList.count > 0) {
NSDictionary *userObject = [ideasArrayList objectAtIndex:0];
NSLog(@"Object and first index of array is %@",userObject);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops something went wrong."
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
[jsonOperation start];
我正在使用AFNetworking 库。
【问题讨论】:
-
你能预览一下
innerObject -
添加有问题的
userObject或innerObject的值。并添加您尝试过的cellforrowatindexpath方法!! -
使用 NSnotificationCenter 并将整个字典数据传递到您想要显示的位置并根据需要相应地解析数据。
-
您将在ideasArrayList 中获取所有响应数据。从该可变数组中,您可以将 idea_title 的值设为 [ideasArrayList Valueforkey:@"idea_title"]。
标签: ios objective-c iphone json uitableview