次のコードがあります。私の問題は、単純な JSON 応答を解析しようとしているのですが、うまくいかないようです。JSON 応答は次のようになります。
{"response":"session_exists"}
以下を使用して JSON をエコーします。
$json_output = array('response' => 'session_exists');
私が知りたいのは、応答が等しいことだけです。session_exists または success のいずれかになります。私は何を間違っていますか?
私はこれまで 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"]);
}