Parse JSON response with AFNetworking

后端 未结 4 1351
长情又很酷
长情又很酷 2020-12-09 19:18

I\'ve setup a JSON post with AFNetworking in Objective-C and am sending data to a server with the following code:

AFHTTPRequestOperationManager          


        
4条回答
  •  没有蜡笔的小新
    2020-12-09 20:13

    In my case, it's looks like (maybe it can helps)

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager POST:url parameters:params
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
              NSDictionary *jsonDict = (NSDictionary *) responseObject;
              //!!! here is answer (parsed from mapped JSON: {"result":"STRING"}) ->
              NSString *res = [NSString stringWithFormat:@"%@", [jsonDict objectForKey:@"result"]];
          } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              //....
          }
     ];
    

    Also would be great to check type of response object (like https://stackoverflow.com/a/21962445/3628317 answer)

提交回复
热议问题