user3745888 user3745888 - 1 year ago 36
iOS Question

Can't I send an array in params with JSONHTTPClient?

I'm trying send some params: a NSString and an NSarray.


have this format when I print this:



But when I add this to params into JSONHTTPClient I get this error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request parameters can be
only of NSString or NSNumber classes.

My code is:

[JSONHTTPClient postJSONFromURLWithString:uploadUrl
params:@{@"idKey":@"689769", @"idFree":myArray}
completion:^(NSDictionary *json, JSONModelError *err)

dispatch_async(dispatch_get_main_queue(), ^{


How can I send an array into params?

Answer Source

If the library doesn't support it, then you probably have to serialise it yourself. You can use the NSJSONSerialization Class for that:

NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:myArray options:kNilOptions error:&error];
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

Now you have myString instead of myArray so it should be happy!