Iphone 如何获取响应字符串并使用ASIHTTPRequest解析它?

Iphone 如何获取响应字符串并使用ASIHTTPRequest解析它?,iphone,objective-c,xcode,cocoa-touch,asihttprequest,Iphone,Objective C,Xcode,Cocoa Touch,Asihttprequest,我正在使用ASIHTTPRequest连接到web服务。我不知道下一步该做什么。当我运行下面提供的代码时,我没有得到任何输出或响应字符串。程序正在运行,没有任何错误。我应该如何获取响应字符串并对其进行解析 代码 -(void)callWebService { //this is a typical url for REST webservice, where you can specify the method that you want to call and the paramet

我正在使用
ASIHTTPRequest
连接到web服务。我不知道下一步该做什么。当我运行下面提供的代码时,我没有得到任何输出或响应字符串。程序正在运行,没有任何错误。我应该如何获取响应字符串并对其进行解析

代码

-(void)callWebService
{

    //this is a typical url for REST webservice, where you can specify the method that you want to call and the parameters directly with GET

    NSURL *url = [NSURL URLWithString:@"https://www.googleapis.com/customsearch/v1?key=AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx=017576662512468239146:omuauf_lfve&q=lectures"];
    //https://www.googleapis.com/customsearch/v1?key=AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx=017576662512468239146:omuauf_lfve&q=lectures&callback=handleResponse    

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

    [request setDidFinishSelector:@selector(requestCompleted:)];
    [request setDidFailSelector:@selector(requestError:)];

    [request setDelegate:self];
      // [request setRequestMethod:@"GET"];
    [request startAsynchronous];
}

- (void)requestCompleted:(ASIHTTPRequest *)request
{
   NSString *responseString = [request responseString];
}

- (void)requestError:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}

你的代码运行得很好。只需在委托方法中添加一些nslog<代码>NSLog(@“ResponseString:%@”,ResponseString)并将错误记录到
NSLog(@“错误:%@,[错误描述])

可能是您的问题是ASIHttpRequest的默认超时10秒

编辑:

编辑2:

 if([responseString length]){
        // do some thing
    }
要将NSString转换为NSDictionary,只需使用


您使用
响应字符串
做什么?你怎么知道它是空的?谢谢你..我应该在哪里添加?我应该在哪里检查响应字符串?我在3天内无法解决这个问题…我没有得到下一步要做什么来解析它..请帮助我运行任何东西来检查响应字符串并解析它?
 if([responseString length]){
        // do some thing
    }
NSDictionary *returnDict = [responseString JSONValue];