user3745888 user3745888 - 1 year ago 93
iOS Question

How to get an array type [1,2] instead of (1, 2) in Objective-c?

I'm trying to send an array in post JSONModel call. I need convett my array to NSString and send the array in format:

[1, 2, 3]

but when I convert this to NSString and print my array, this has the format:

(1, 2, 3)

NSMutableArray *array= [NSMutableArray arrayWithObjects:@"1", @"2",@"3",@"4", nil];
NSString *arraString = [NSString stringWithFormat:@"%@", arr];

How can I create this with

Answer Source
NSMutableArray *array= [NSMutableArray arrayWithObjects:@"1", @"2",@"3",@"4", nil];
NSData *jsond = [NSJSONSerialization dataWithJSONObject: array options:NSJSONWritingPrettyPrinted error:NULL];
NSString *json = [[NSString alloc] initWithData:jsond encoding:NSUTF8StringEncoding];

NSLog(@"%@", json);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download