gpt4 book ai didi

ios - 如何在ios中发送多个参数?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:56:55 26 4
gpt4 key购买 nike

如何发送json格式的参数?

以下是我的输入参数:

[
{
"LoginID":151,
"UserID":0,
"SubUserID":0,
"WorkGroupID":92,
"WorksFor":"Doctor",
"UserWorkGroup":0
},
{
"SortingName":"",
"Searching":true,
"SortingOrder":"Desc",
"RecordsCount":10,
"PageIndex":0
}
]

之前我发送的参数如下:

[getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc] initWithObjectsAndKeys:@"55",@"LoginID",@"0",@"UserID",@"0",@"SubUserID",@"90",@"WorkGroupID",@"Doctor",@"WorksFor",@"0",@"UserWorkGroup",nil] andRequestType:@"POST"];

如何像这样发送,但现在我需要添加上面提到的更多输入?

最佳答案

只需使用以下代码..

NSMutableArray * myArray = [[NSMutableArray alloc]init];

NSMutableDictionary * myData = [[NSMutableDictionary alloc]init];
[myData setValue:@"151" forKey:@"LoginID"];
[myData setValue:@"0" forKey:@"UserID"];
[myData setValue:@"0" forKey:@"SubUserID"];
[myData setValue:@"92" forKey:@"WorkGroupID"];
[myData setValue:@"Doctor" forKey:@"WorksFor"];
[myData setValue:@"0" forKey:@"UserWorkGroup"];

[myArray addObject:myData];

myData = [[NSMutableDictionary alloc]init];
[myData setValue:@"," forKey:@"SortingName"];
[myData setValue:@"1" forKey:@"Searching"];
[myData setValue:@"Desc" forKey:@"SortingOrder"];
[myData setValue:@"10" forKey:@"RecordsCount"];
[myData setValue:@"0" forKey:@"PageIndex"];
[myArray addObject:myData];

NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:myArray options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
NSLog(@"Your final jsonData as string:\n%@", jsonString);

如果你想将这个数据发送到服务器,那么你可以使用这个代码:

NSData *dataToSend = [NSJSONSerialization dataWithJSONObject:myArray options:0 error:nil];

[getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc] initWithObjectsAndKeys:dataToSend] andRequestType:@"POST"];

关于ios - 如何在ios中发送多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995718/

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