问题: 小弟菜鸟一个,需要将一个对象数组生成一个jsonarray,如下,我想将actorhalls这个对象数组转换为一个json的字符串。
NSMutableArray *actorhalls=[[NSMutableArray alloc]init];
for (int i=0; i<[self.channels count]; i++) {
ExecplanActosHall *actorhall=[[ExecplanActosHall alloc]init];
actorhall.ownerName=channel.channelName;
actorhall.ownerId=channel.channelId;
actorhall.channelId=[MXUser currentUser].channelId;
actorhall.ownerType=17;
[actorhalls addObject:actorhall];
}
解答:
遍历数组中的值,并按json格式去 格式化每一组数组,拼接起来即可
以下是用例,我测试了下,是可以的,不知道有没有更加高效的办法