ios - storing [NSNull null] values in NSUserDefaults, from JSON serialization, causes unwanted exceptions -
I found the app where I use a JSON based API. As part of JSON, often values are set to "blank". It can be normal:
{"data": ["one", "two", "three"] , "Name": blank, otherwise: 10} Recently I tried to store a diverse NSDictionary hierarchy that was converted from the JSON object into NSUserDefaults. Unfortunately, this causes an exception if there is zero data, converting to [NSNull null] in iOS is evident that it can not be saved in priority
I was thinking that someone worked on it earlier is? I tried to add some arguments, which, with limited success, first remove all the empty values from JSON, but it is inappropriate to modify the data before saving it. Do you have a better way of handling it?
You can first convert your NSDictionary into NSData, then store it safely in NSUserDefaults ( Because NSNull corresponds to NSCoding). // archive NSDTA * data = [NSKEADArtic archivesDatabaseAssociation: dictionary]; [[NSUserDefaults standard standard defaults] setObject: For data: @ "key"]; // Unsource NSDTA * new data = [[NSUserDefaults standard user default] objectfore: @ "key"]; NSDictionary * newDict = [NSKeyedUnarchiver unarchiveObjectWithData: newData]; Edit: The original data object was being referenced instead of the new data object.
Comments
Post a Comment