gpt4 book ai didi

ios - 如何在 Objective-c 中获取数组类型 [1,2] 而不是 (1, 2)?

转载 作者:行者123 更新时间:2023-11-29 00:40:53 25 4
gpt4 key购买 nike

我正在尝试在 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);

如何使用 [] 格式创建此内容?

最佳答案

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

关于ios - 如何在 Objective-c 中获取数组类型 [1,2] 而不是 (1, 2)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39539360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com