How to send NSArray to web service

大憨熊 提交于 2019-12-04 22:03:25

You can send an NSArray to webservice

NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:yourArray options:NSJSONWritingPrettyPrinted error:nil];
         NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
         NSLog(@"FemaleFriendList:\n%@", jsonString);

You can't send an NSArray to webservice, but if you want to do so then first convert that NSArray to NSString like below

NSString *stringDelete = [YourNSArray componentsJoinedByString:@","];

then pass that NSString to webservice.Let me know whether is it working or not!!!!!!Happy Coding...!!!

One option is use NSJSONSerialization to convert array into string and vice-versa which is available form iOS 5

NSArray *myArrDate = any Data ....
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myArrDate
                                                   options:0
                                                     error:nil];
if (!jsonData) {
   NSLog(@"error");
 } else {
  NSString *JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
  NSLog(@"%@",JSONString);
}

Refer convert-nsdictionary-or-nsarray-to-json-nsstring-and-vice-versa link for more info.

You are sending an NSString (%@ , myArray) as parameter and the webservice expects an IList object. Why do not you serialize the NSArray before sending it? For example you could use JSON.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!