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

编程入门 行业动态 更新时间:2024-10-26 01:25:01
本文介绍了如果任何值为NULL,则CFPropertyListCreateDeepCopy返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下 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

本文发布于:2023-10-19 19:22:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508520.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:值为   NULL   nil   CFPropertyListCreateDeepCopy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!