gpt4 book ai didi

ios - AFNetworking - NSMutableDictionary 参数

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:02 25 4
gpt4 key购买 nike

我正在尝试构建我的 NSMutableDictionary 以发送到使用 AFNetworking 框架的请求,但我似乎对如何正确执行它感到很困惑。

这是服务器所期待的

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

我试过这样

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"]);

希望有人能帮帮我谢谢

最佳答案

您可以使用下面的内容来获取您的服务器想要的内容。确保您的服务器将从字典中解码数据

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

关于ios - AFNetworking - NSMutableDictionary 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42288947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com