-1
我有這個方法通過JSON陣列登錄,這一切都確定,但它不是在JSON狀態不進入,如果
if(json2 == 0)
但NSLog的輸入告訴我,它的值是0,我怎麼能解決這個 ?該方法正在工作,但它沒有進入,如果。
-(void)loginAPICall
{
NSString *device_name = @"Iphone";
NSString *device_modelname = @"5";
NSString *gcm_id = @"1234567890";
NSString *user = _user.text;
NSString *pass = _pass.text;
// SENDING A POST JSON
NSString *post = [NSString stringWithFormat:@"device_name=%@&device_modelname=%@&gcm_id=%@&username=%@&password=%@", device_name, device_modelname, gcm_id, user, pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[[NSURL alloc] initWithString:@"http://192.168.1.110/project/api"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLResponse *requestResponse;
NSData *requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:nil];
NSError *error;
NSMutableDictionary *getJsonData = [NSJSONSerialization
JSONObjectWithData:requestHandler
options:NSJSONReadingMutableContainers
error:&error];
if(error)
{
NSLog(@"%@", [error localizedDescription]);
}
else {
NSArray *json = getJsonData[@"login"];
for (NSDictionary *jsn in json)
{
NSLog(@"id: %@ ", jsn[@"id_user"]);
}
NSArray *json2 = getJsonData[@"status"];
if(json2 == 0){
NSLog(@"Cannot login");
}
NSLog(@"value:%@",json2);
}
}
你可以發佈你的json數據嗎? – 2014-12-03 12:51:37
array == 0你在做什麼? – sanjeet 2014-12-03 12:51:50
NSLog告訴你*完全是什麼* ??? – 2014-12-03 13:02:12