2

I'm trying to build my NSMutableDictionary to send to a request using the AFNetworking framework, but it seems that I'm quite confused about how to do it properly.

Here's what the server is expecting

{
"do":"timeline",
"what":"posting",
"session":"",
"data":{
"status_timeline":"",
    "with_timeline":"",
    "location_timeline":"",
    "category_timeline":"",
    "privacy_timeline":""  
}

and I've tried like this

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:@"timeline" forKey:@"do"];
    [dict setValue:@"posting" forKey:@"what"];
    [dict setValue:session forKey:@"session"];
    NSLog(@"Session %@",  [dict  valueForKey:@"session"]);

I hope someone can help me thank's

Irwan Madness
  • 1,236
  • 2
  • 13
  • 19
  • Welcome to SO. This is your second question on "how do I do xyz" . This isn't a tutorial site, you need to specify your problems, what you have tried so far, what results you are getting, what errors you run into and what you were expecting, together with a specific question to a specific problem you need to solve. Please read through http://stackoverflow.com/help/how-to-ask before posting further questions to avoid flags. There are multiple threads with what you are trying to achieve, example: http://stackoverflow.com/questions/34434728/how-to-post-json-parameters-using-afnetworking –  Feb 17 '17 at 03:43

1 Answers1

1

You can use below to get input what your server want. Make sure your server will decode the data from dictionary.

  NSMutableDictionary *dicData = [NSMutableDictionary new];
    dicData[@"status_timeline"] = @"";
    dicData[@"with_timeline"] = @"";
    dicData[@"location_timeline"] = @"";
    dicData[@"category_timeline"] = @"";
    dicData[@"privacy_timeline"] = @"";
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicData options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];


    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:@"timeline" forKey:@"do"];
    [dict setValue:@"posting" forKey:@"what"];
    [dict setValue:@"" forKey:@"session"];
    [dict setValue:jsonString forKey:@"data"];
    NSLog(@"Your Main Dic: %@",  dict);
Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56