Ios 循环遍历数组元素
我正在开发一个应用程序,因为我曾经通过Web服务将我的联系人号码发送到服务器。这里我将我的联系人号码作为一个数组,但是如何在for-loop上发送我的联系人数组。这里是服务链接Ios 循环遍历数组元素,ios,objective-c,xcode,for-loop,ios8,Ios,Objective C,Xcode,For Loop,Ios8,我正在开发一个应用程序,因为我曾经通过Web服务将我的联系人号码发送到服务器。这里我将我的联系人号码作为一个数组,但是如何在for-loop上发送我的联系人数组。这里是服务链接 http://project.in/project-contacts.php 参数联系人号码[] 下面是我尝试的代码 NSString *postVarArrayString = @""; NSString *separator = @"?"; for (int i=0; i<[_numberAr
http://project.in/project-contacts.php
参数联系人号码[]
下面是我尝试的代码
NSString *postVarArrayString = @"";
NSString *separator = @"?";
for (int i=0; i<[_numberArray count]; i++) {
if (i>0) {
separator = @"&";
}
postVarArrayString = [NSString stringWithFormat:@"%@%@myArray[]=%ld", postVarArrayString, separator, (long)[[_numberArray objectAtIndex:i] integerValue]];
}
// url
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:
@"http://project.in/project-contacts.php"
@"%@"
, postVarArrayString]
];
NSLog(@"qq=%@", [url absoluteString]);
在这里,我如何通过Web服务发送联系人数组。请您建议我如何发送,谢谢。将字典作为参数发送,以便您的php脚本使用$\u POST变量获取这些参数 使用库的示例
将整个阵列发送到服务器。。让服务器端脚本完成这项工作。
NSArray *keys = [NSArray arrayWithObjects: @"key1", @"key2", nil];
NSArray *values = [NSArray arrayWithObjects: @"value1", @"value2", nil];
NSDictionary *parameters = [NSDictionary dictionaryWithObjects: values Keys: keys];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL[NSURL URLWithString:@"Your server url"];
NSURLRequest *request = [client requestWithMethod:@"POST" path:@"path" parameters:parameters];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}];
[operation start];