问题
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 fails to process array / dictionary containing 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
Thanks in advance.
回答1:
After few hours of workaround, I have solved this issue by below way.
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];
So there will be no null characters in your JSON object, hence no issue with using CFPropertyListCreateDeepCopy
.
Cheers!!
来源:https://stackoverflow.com/questions/34219638/cfpropertylistcreatedeepcopy-returns-nil-if-any-value-is-null