- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *site_url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/json/data/post?sid=%@", SECURE, PASSCODE]];
NSData *jsonData = [NSData dataWithContentsOfURL:site_url];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.items = dataDictionary;
}
我想解析json數據。它適用於來自活動服務器的數據。但是,當我將鏈接更改爲http://localhost:8090
時。它停止工作。如何在objective-c中使用localhost中的json數據?
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
我可以從網絡瀏覽器的數據訪問它。有誰知道這是爲什麼?
你的jsonData是零,可以從你的jsonData發佈NSLog – CarlJ
NSLog只顯示jsonData:(null) – tipsywacky
我們是在談論模擬器還是實際的設備? –