获取JSON响应问题

时间:2015-12-31 09:25:34

标签: ios objective-c

目前我正在使用.net Api获取回复

这是我的iOS源代码:

-(void)getUserNameFromFacebbok: (NSString*)newUserName withFacebookId: (NSString*)newFbId withFacebookLoginEmailId: (NSString*)newEmailId withProfilePicUrl: (NSString*)newProfilePicUrl{
NSString * fbApiURLStr =[NSString stringWithFormat:@"http://example.com/api/v1/FacebookUserLogin?UserName=%@&id=%@&emailid=%@&facebookurl=%@",
                       newUserName,
                       newFbId,
                       newEmailId,
                       newProfilePicUrl];

NSMutableURLRequest *dataRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:fbApiURLStr]];
NSHTTPURLResponse *response =[[NSHTTPURLResponse alloc] init];
NSError* error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:dataRequest returningResponse:&response error:&error];
facebookLoginResponseDict = [NSJSONSerialization JSONObjectWithData:responseData
                                                    options:0
                                                      error:&error];
}

我没有收到任何回复 dataRequest 参数====>目前我正在 {URL:(null)}

你能帮我解决一下如何解决这个问题

1 个答案:

答案 0 :(得分:0)

抱歉,我找到了正确的解决方案,如

NSURL *url = [NSURL URLWithString:@"http://example.com/api/v1/FacebookUserLogin?UserName=Brahmam&id=4654566&emailid=ghjnghjnhgh@gmail.com&facebookurl=https://fbjghjghjghjghmkjhgmhjkmhjmh"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSURLResponse *response;
NSError *error;
//send it synchronous
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// check for an error. If there is a network error, you should handle it here.
if(!error)
{
    //log response
    NSLog(@"Response from server = %@", responseString);
}