如何在Objective-C中获取数组types而不是(1,2)?

我试图发送后JSONModel调用数组。 我需要将我的数组转换为NSString并以格式发送数组:

[1, 2, 3] 

但是当我将其转换为NSString并打印我的数组时,它的格式为:

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

我怎样才能用[]格式创build这个?

 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); 

你可以做的是

 NSString *joinedString = [array componentsJoinedByString:@","]; NSString *arraString = [NSString stringWithFormat:@"(%@)", joinedString]; 

希望这会解决你的问题