我正在使用一种方法来调用Web服务并在服务器上上传转录音频文件。方法如下:

    - (NSDictionary *)UploadTranscriptionAudio:(NSString *)uploadfor forPN_ID:(NSString
   *)pn_id forTaskFlag:(NSString *)taskflag documentPath:(NSString *)documentpath
    forUserName:(NSString *)username file_path_msd:(NSString *)file_path_msd
   audioFilePath:(NSString *)audiofilepath{

NSDictionary *response = nil;


NSURL * url = [NSURL URLWithString:[AppDelegate sharedInstance].str_webServiceUrl];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request setPostValue:uploadfor forKey:@"Uploadfor"];
[request setPostValue:pn_id forKey:@"PNID"];
[request setPostValue:taskflag forKey:@"task_flag"];
[request setPostValue:documentpath forKey:@"Path"];
[request setPostValue:username forKey:@"Username"];
[request setPostValue:file_path_msd forKey:@"file_path_msd"];
[request setFile:audiofilepath forKey:@"uploadedfile"];

[request startSynchronous];

NSError *error = [request error];
if (!error) {
    response = (NSDictionary*)[request responseString];
    NSLog(@"Response = %@",response);
    return response;
}
return response;

}

此方法仍然返回NSstring作为响应。我想要的是该方法应返回NSDictionary。因为我必须在其他地方使用该字典中键的值。有人可以帮我这个忙吗?

最佳答案

您好shikher maddy说的对,您可以按以下方式解析字符串

if (responseString == NULL) {
    // do something u want
} else {
    NSDictionary *jsonResponse = [responseString JSONValue];
    NSLog(@"  %@",jsonResponse);
}

关于ios - 返回NSString而不是NSDictionary,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16737524/

10-12 14:38