[英]CFPropertyListCreateDeepCopy returns nil if any value is NULL
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. 我正在使用以下
CoreFoundation
函数CFPropertyListCreateDeepCopy:
用于将不可变对象转换为可变对象。如果任何对象为NULL,则CFPropertyListCreateDeepCopy
返回空。是否有任何解决方法。
self.packageArray = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (CFPropertyListRef)self.packageArray , kCFPropertyListMutableContainersAndLeaves));
CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull CFPropertyListCreateDeepCopy无法处理包含NSNull的数组/字典
sample code 示例代码
NSArray *immutable = @[ @"a", [NSNull null], @"c" ];
NSMutableArray *mutable = (__bridge
id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge
CFArrayRef)immutable, kCFPropertyListMutableContainers);
sample json response from this link 来自此链接的示例json响应
Thanks in advance. 提前致谢。
After few hours of workaround, I have solved this issue by below way. 经过几个小时的解决方法,我已经通过以下方式解决了这个问题。
Just place below line when converting API response to JSON Object. 将API响应转换为JSON对象时,只需放在下面。
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];
So there will be no null characters in your JSON object, hence no issue with using CFPropertyListCreateDeepCopy
. 因此,JSON对象中不会出现空字符,因此使用
CFPropertyListCreateDeepCopy
没有问题。
Cheers!! 干杯!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.