返回NSString而不是NSDictionary

时间:2013-05-24 14:35:31

标签: ios json asiformdatarequest

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

2 个答案:

答案 0 :(得分:1)

你好shikher maddy说对了你可以解析字符串如下

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

答案 1 :(得分:1)

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

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

NSDictionary *dictionnary = [parser objectWithString:responseString error:nil];