我有以下代码。我的问题是我试图解析一个简单的 JSON 响应,但它似乎不起作用。JSON 响应如下所示:
{"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=email@email.com&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"]);
}