다음 코드가 있습니다. 내 문제는 간단한 JSON 응답을 구문 분석하려고하지만 작동하지 않는 것 같습니다. JSON 응답은 다음과 같습니다 : I이 (가) JSON 반향 다음을 사용iOS에서 JSON이 파싱되지 않습니까?
{"response":"session_exists"}
: 내가 알고 싶은 모든 응답이 동일 무엇
$json_output = array('response' => 'session_exists');
입니다. session_exists이거나 성공한 것입니다. 내가 도대체 뭘 잘못하고있는 겁니까?
전 JSON에서 일한 적이 없으므로 누구든지 나를 도울 수 있다면이 프로젝트에 도움이 될 것입니다.
감사합니다. 당신이이하는 말처럼 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 (@ "% @", responses)의 출력; –