如何在Objective-c中获得数组类型[1,2]而不是(1,2)? [英] How to get an array type [1,2] instead of (1, 2) in Objective-c?

查看:88
本文介绍了如何在Objective-c中获得数组类型[1,2]而不是(1,2)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JSONModel调用后发送一个数组.我需要将我的数组转换为NSString并以以下格式发送该数组:

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] 

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

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

这篇关于如何在Objective-c中获得数组类型[1,2]而不是(1,2)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆