Getting a web service response in the Format string

I use the Afnetworking Framework in my project, but I get the answer in a lowercase format. I want to get the value "Data" in the answer below -

"{\"Result\":\"Success\",\"Data\":\"intro-1898-1449000428650.mp4\"}" 

I used the following code:

 [Helper PostWebServiceRequest:kIntrovideo InputParameters:parameters competion:^(BOOL result, NSDictionary *response) { if (result){ NSLog(@"response : %@",response); NSString *data= [NSString stringWithFormat:@"%@",response ]; NSError *jsonError; NSData *objectData = [data dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError]; 
+5
source share
2 answers

since your response object seems to be an array and not (as indicated) by a dictionary, try the following:

 NSString *jsonString = ((NSArray *)response).firstObject; NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil]; NSString *data = jsonObject[@"Data"]; 
+3
source

Not sure, but it seems that the server cannot pass the object to Json, it should pass a link to the place from where you can load this data.

0
source

Source: https://habr.com/ru/post/1246829/


All Articles