我有一个名为child_list
的数组,如child_list:“9,8,21,22,20,24,25”,在索引0时将它转换为NSString
,当我将它转换为字符串时,它的工作,但是当我使用NSMutableArray
时,它崩溃,我不知道为什么。iOS如何以逗号分隔的数组对象转换为字符串?
我的代码是在这里:
if([theDictionary objectForKey:@"child_list"])
{
NSString *str = [[theDictionary objectForKey:@"child_list"]objectAtIndex:0];
NSLog(@"Child List %@",str);
_child_list = [[NSMutableArray alloc ]initWithObjects: [str componentsSeparatedByString:@","], nil];
}
当破发点来吧str
它显示的结果,当谈到对_child_list
坠毁。
做的NSLog(@ “儿童名单%@”,STR);这个日志打印“9”。或者只是“9” – Vaisakh
将child_list创建为NSMutableArray。它会完美地工作。不需要改变任何东西。 –
如何尝试这样做:_child_list = [str componentsSeparatedByString:@“,”]。mutableCopy –