我有下面的代碼。我的問題是我試圖解析一個簡單的JSON響應,但它似乎並沒有工作。 JSON響應看起來是這樣的:JSON不解析在iOS?
{"response":"session_exists"}
我用下面的呼應JSON:
$json_output = array('response' => 'session_exists');
所有我想知道的是什麼樣的反應是公平的。這將是session_exists或成功。我究竟做錯了什麼?
我還沒有和JSON工作過,所以如果有人可以幫助我,這將真正幫助我打算在這個項目上。
謝謝!
- (IBAction)login:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://localhost/lookin_chill/Website/api/api_account.php?action=login&[email protected]&password=pass123"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
[data appendData:theData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
responses = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
NSLog(@"%@", responses);
NSLog(@"%@", [[responses objectAtIndex:0] objectForKey:@"response"]);
}
是什麼'的NSLog(@ 「%@」,響應)的輸出;' –