我有这个问题。我正在尝试使用来自使用 NSJSONSerialization 制作的 JSON 字典的数据构建 UITableView。我不知道从哪里开始。我已经尝试了 3 天,但筒仓一无所获。这是我想出的代码:
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define kJsonURL [NSURL URLWithString: @"http://rs-hosting.nl/panel/serverstatus_json.php"]
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:kJsonURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSDictionary *clients = [json objectForKey:@"announcements"];
NSArray *announcements = [clients objectForKey:@"announcement"];
NSDictionary* announcement = [announcements objectAtIndex:1];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
@end
我能够在标签中的单个视图上显示标签中的内容,但我不知道如何将 json 中的所有数据添加到表中。有人可以治愈我吗?
SDK:5.1 OSX:10.7.3 XCODE:4.3.1
提前 Tnx