【发布时间】:2015-12-05 05:11:42
【问题描述】:
我创建了一个自定义类型的框架,我添加到我的应用程序中,在那个自定义框架中我添加了简单的方法,它将返回正常的字符串,但我的问题是我想使用那个框架作为一个 API 调用,如登录和注册等,我使用 NSJSONSERIALIZATION 从 json 获取数据,它会返回值,但我想在我的应用程序中使用该数据,谁能告诉我,我是自定义类型的新手框架和所有;
-(void )JsonData :(NSDictionary *)dictionary method:(NSString *)method url:(NSString *)url {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:method];
NSLog(@"apiCall RequestUrl: %@, HTTPMethod: %@, RequestData: %@", request.URL.absoluteString, method, dictionary);
if ([method isEqualToString:@"POST"] || [method isEqualToString:@"PUT"])
{
NSData *dataToSend = [NSJSONSerialization dataWithJSONObject:(NSDictionary *)dictionary options:0 error:nil];
[request setHTTPBody:dataToSend];
}
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue new] completionHandler:^(NSURLResponse *response, NSData *data, NSError *responseError)
{
NSDictionary *responseData;
if (responseError)
{
responseData = [NSDictionary dictionaryWithObjectsAndKeys:
@"Error", @"status",
responseError.localizedDescription, @"message",
nil];
}
else if ([(NSHTTPURLResponse *)response statusCode] != 200)
{
responseData = [NSDictionary dictionaryWithObjectsAndKeys:
@"Error", @"status",
@"Invalid Response from server.", @"message",
nil];
}
else if ([[Response getCustomStatus:(NSHTTPURLResponse *)response] isEqualToString:@"invalid_session"])
{
responseData = [NSDictionary dictionaryWithObjectsAndKeys:
@"Error", @"status",
@"Your session has been expired.", @"message",
nil];
}
else
{
responseData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&responseError];
}
NSLog(@"apiCall ResponseData: %@", responseData);
CustomerInfo *customer = [[CustomerInfo alloc]init];
customer.session = [[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"session"];
NSLog(@"JsonData:%@",[[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"session"]);
NSLog(@"Data:%@",customer.session);
customer.groupID = [[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"group_id"];
NSLog(@"%@",[[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"group_id"]);
NSLog(@"Data:%@", customer.groupID );
customer.cutomerID = [[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"customer_id"];
NSLog(@"%@",[[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"customer_id"]);
NSLog(@"Data:%@", customer.cutomerID );
customer.stylistProfilepicUrl = [[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"stylist_profile_url"];
NSLog(@"%@",[[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"stylist_profile_url"]);
NSLog(@"Data:%@", customer.stylistProfilepicUrl);
customer.fbUserID = [[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"fb_user_id"];
NSLog(@"%@",[[[responseData objectForKey:@"data"]objectAtIndex:0]objectForKey:@"fb_user_id"]);
NSLog(@"Data:%@", customer.fbUserID );
}];
}
这是我的框架代码,
在我的应用程序中,我只是调用此代码并发送参数,
我得到了响应,但是当我打印数据时,它在我的应用程序中显示空值,
任何人都可以建议我或给我任何链接或教程
【问题讨论】:
标签: ios objective-c frameworks