1

我正在使用一种方法来调用 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。因为我必须在其他地方使用该字典中键的值。有人可以帮我解决这个问题。

4

2 回答 2

1

你好 shikher maddy 说正确的 nu 可以解析字符串如下

if (responseString == NULL) {
    // do something u want
} else {
    NSDictionary *jsonResponse = [responseString JSONValue];
    NSLog(@"  %@",jsonResponse);
}
于 2013-05-24T14:50:55.510 回答
1

如果我是你,我会像这样使用SBJSONParser

SBJsonParser *parser=  [[SBJsonParser alloc] init];

NSDictionary *dictionnary = [parser objectWithString:responseString error:nil];
于 2013-05-24T14:58:08.920 回答