我想執行賽格瑞如果登錄響應是與響應JSON驗證登錄
登錄響應:
{ 「登錄」:[{ 「參數userid」: 「12」, 「名稱」:」 (abc)「}]}
我該如何驗證它?
下面是我提取響應的代碼。
-(IBAction)loginbutton:(id)sender {
NSString *post = [[NSString alloc] initWithFormat:@"email==%@&pass==%@",self->email.text,self->passwrd.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:@"URL"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"Login response: is %@",str); //getting response
}
解析JSON響應,並期待在您需要驗證的任何值。 Objective-C中有無數解析JSON的例子。 – rmaddy
@rmaddy我已經提到了我在問題中的回答,我想驗證該問題以繼續登錄。 –
沒錯。我告訴你你必須做什麼。您需要解析JSON並從中獲取所需的值。嘗試使用您可以找到的無數現有示例來解析JSON。然後根據需要更新您的問題,一旦你到達那裏。 – rmaddy