如果任何值为NULL,则CFPropertyListCreateDeepCopy返回nil

084*_*442 6 arrays objective-c core-foundation ios

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

self.packageArray  = CFBridgingRelease(CFPropertyListCreateDeepCopy(NULL, (CFPropertyListRef)self.packageArray , kCFPropertyListMutableContainersAndLeaves));
Run Code Online (Sandbox Code Playgroud)

CFPropertyListCreateDeepCopy无法处理包含NSNull的数组/字典

示例代码

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

来自此链接的示例json响应

提前致谢.

Sim*_*.IC 0

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

将 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];
Run Code Online (Sandbox Code Playgroud)

因此,您的 JSON 对象中不会有空字符,因此使用CFPropertyListCreateDeepCopy.

干杯!!