1

I am using a method to call the Web Services and Upload the Transcription Audio File On the Server. The method is as follows:

    - (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;

}

This method is still returning me a NSstring in response. What i want is that this method should return me a NSDictionary. As I have to use the value for the keys inside that dictionary somewhere else. Can somebody help me on this.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Shikhar
  • 159
  • 1
  • 11
  • is it a JSON string? how should it be converted? – Wain May 24 '13 at 14:37
  • 5
    The call to `[request responseString]` returns an `NSString`. Casting it to an `NSDictionary` doesn't magically convert it. It is still an `NSString`. You need to parse the string and create a dictionary from the results of parsing. – rmaddy May 24 '13 at 14:38
  • thanks! rmaddy but can u show me that with some code that how to parse that string. – Shikhar May 24 '13 at 14:42
  • Edit into your question a maybe 100 character sample of the string you're getting, so we can see if it is JSON (which is probably the case). – Hot Licks May 24 '13 at 14:43
  • 1
    (There are easily 200 threads here on how to parse JSON in iOS.) – Hot Licks May 24 '13 at 14:43
  • possible duplicate of [How do I parse JSON with Objective-C?](http://stackoverflow.com/questions/5547311/how-do-i-parse-json-with-objective-c) – Caleb May 24 '13 at 14:50
  • @Shikhar Without knowing what your result looks like there is no point in trying to give a specific answer. As "Hot Licks" said, post a typical response. If it's JSON, then do a search on parsing JSON. You will find many examples. – rmaddy May 24 '13 at 14:50

2 Answers2

1

hello shikher maddy says right n u can parse string as follow

if (responseString == NULL) {
    // do something u want
} else {
    NSDictionary *jsonResponse = [responseString JSONValue];
    NSLog(@"  %@",jsonResponse);
}
Regexident
  • 29,441
  • 10
  • 93
  • 100
Kanhaiya Sharma
  • 1,040
  • 8
  • 20
  • We don't know that the result is JSON. The OP has not yet made such a claim. – rmaddy May 24 '13 at 14:52
  • This is the response string which I am getting and certainly ii is JSON. Response = {"code":"1","description":"File Uploaded Successfully","file":"IMSEMROH_7674.caf","file_msd":"IMSEMROH_7674"} – Shikhar May 24 '13 at 14:57
  • 1
    Also, `JSONValue` isn't a standard method of NSString. Is it a category added by some 3rd party framework? If so it needs stating what this is, with a link. – Steve Waddicor May 24 '13 at 14:58
1

If I were you I would use SBJSONParser like this:

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

NSDictionary *dictionnary = [parser objectWithString:responseString error:nil];
Mongi Zaidi
  • 1,043
  • 10
  • 15