【问题标题】:CFPropertyListCreateDeepCopy returns nil if any value is NULL如果任何值为 NULL,CFPropertyListCreateDeepCopy 将返回 nil
【发布时间】:2016-03-17 03:16:02
【问题描述】:

我正在使用以下CoreFoundation 函数CFPropertyListCreateDeepCopy: 用于将不可变对象转换为可变对象。如果任何对象为 NULL,则 CFPropertyListCreateDeepCopy 返回空。是否有任何解决方法。

self.packageArray  = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (CFPropertyListRef)self.packageArray , kCFPropertyListMutableContainersAndLeaves));

CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

示例代码

 NSArray *immutable = @[ @"a", [NSNull null], @"c" ];      
 NSMutableArray *mutable = (__bridge 
   id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge 
        CFArrayRef)immutable, kCFPropertyListMutableContainers);

来自this link的示例json响应

提前致谢。

【问题讨论】:

  • 你能提供一个最小的代码示例吗?

标签: ios objective-c arrays core-foundation


【解决方案1】:

经过几个小时的解决方法,我已经通过以下方式解决了这个问题。

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

因此您的 JSON 对象中不会有空字符,因此使用 CFPropertyListCreateDeepCopy 没有问题。

干杯!!

【讨论】:

    猜你喜欢
    • 2012-08-19
    • 1970-01-01
    • 2012-06-15
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多