如何发送json 格式的参数?
以下是我的输入参数:
[
{
"LoginID":151,
"UserID":0,
"SubUserID":0,
"WorkGroupID":92,
"WorksFor":"Doctor",
"UserWorkGroup":0
},
{
"SortingName":"",
"Searching":true,
"SortingOrder":"Desc",
"RecordsCount":10,
"ageIndex":0
}
]
之前我发送的参数如下:
[getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc] initWithObjectsAndKeys"55",@"LoginID",@"0",@"UserID",@"0",@"SubUserID",@"90",@"WorkGroupID",@"Doctor",@"WorksFor",@"0",@"UserWorkGroup",nil] andRequestType"OST"];
如何像这样发送,但现在我需要添加上面提到的更多输入?
Best Answer-推荐答案 strong>
只需使用以下代码..
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:@"ageIndex"];
[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:@"OST"];
关于ios - 如何在ios中发送多个参数?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/36995718/
|