我正在使用以下 CoreFoundation 函数 CFPropertyListCreateDeepCopy: 将不可变对象转换为可变对象。如果任何对象为NULL,则 CFPropertyListCreateDeepCopy 返回空。是否有任何解决方法。
I am using the following CoreFoundation function CFPropertyListCreateDeepCopy: for converting the immutable objects to mutable objects.If any of the object is NULL the CFPropertyListCreateDeepCopy returning empty .Is there any work around for this.
self.packageArray = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (CFPropertyListRef)self.packageArray , kCFPropertyListMutableContainersAndLeaves));CFPropertyListCreateDeepCopy无法处理包含NSNull的数组/字典
示例代码
NSArray *immutable = @[ @"a", [NSNull null], @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers);来自此链接
提前致谢。
推荐答案经过几个小时的解决方法,我已经通过以下方式解决了这个问题。
After few hours of workaround, I have solved this issue by below way.
Just将API响应转换为JSON对象时放在下面。
Just place below line when converting API response to JSON Object.
responseString=[responseString stringByReplacingOccurrencesOfString:@"\":null" withString:@"\":\"\""];//To Handle Null Characters //Search for below line in your parsing library and paste above code data = [responseString dataUsingEncoding:NSUTF8StringEncoding];因此JSON对象中不会出现空字符,因此使用 CFPropertyListCreateDeepCopy 。
So there will be no null characters in your JSON object, hence no issue with using CFPropertyListCreateDeepCopy.
干杯!!
更多推荐
如果任何值为NULL,则CFPropertyListCreateDeepCopy返回nil
发布评论