Remove NULL from the dictionary
We are unable to do local persistence if nullis present in the data during processing of the data sent by the server. When you use NSUserDaults
save locally, a crash occurs if the value of one of the fields is a null value.
Cause of NULL generation
null is the background when processing the data, if the default value is not set value
, the database is populated by default value, is null value, from the server, our JSON or XML resolves to a null value.
Solutions
- Server-side processing, so that all fields corresponding to the default value is not NULL
- Local do delete null processing
Local do delete null processing
If the database is processed, you can populate the database with the unfilled value
fill as "" .
If it is handled locally, I am personally working by adding categories to achieve the effect.
The code is as follows:
Nsdictionary+mydictionary.h
***********************************
#import <Foundation/Foundation.h> @interface nsdictionary (mydictionary)-(nsdictionary *) deleteallnullvalue;@ End
//*********************************************************************
Nsdictionary+mydictionary.m
Nsdictionary+mydictionary.m#import "nsdictionary+ MyDictionary.h "@implementation nsdictionary (MyDictionary)-(nsdictionary *) deleteallnullvalue{ Nsmutabledictionary *mutabledic = [[Nsmutabledictionary alloc] init]; For (NSString *keystr-Self.allkeys) { if ([[self objectforkey:keystr] isequal:[nsnull null]) { [mutabledic se tobject:@ "" Forkey:keystr]; } else{ [mutabledic setobject:[self objectforkey:keystr] forkey:keystr]; } } return mutabledic;} @end
Learning: http://www.ithao123.cn/content-10842398.html
Request SQL data is present <null>, the workaround