, nil and nil and null judgments
During the development process, we return JSON data in the background via HTTP requests, and sometimes the value of a field in the data is null~, and then we assign this value to Nsarray,nsdictionary, or nsstring, and then we will determine if this value is null, the processing , and usually we will write when the inertial thinking is judged: if (dict = = nil) or if (dict = = nil) or if (dict = = NULL) or if (dict isequal nil), we find that it is not good to use, Did not play the role of judgment ~ later I found that the original can not be judged.
Simply put, it is when the dictionary, the array is null, the output of the background print is this:
Then, we need to use [NSNull NULL] to judge the code, as follows:
Isequal:[nsnull NULL] It was done, and Nsarray was the same.
Console printing: str= (null) means that a string or array or dictionary is a null pointer, rather than an empty string, that is used directly when judging:
The IF (str = = nil) is available. As shown in the following:
While the console prints: str = <NULL>, which represents an empty string, the assignment is null, the pointer is present, but the content is empty, this judgment needs to be used:
if (str is equal [NSNull null]), because on iOS, the content is empty can not be easily judged str==null (null on iOS [NSNull null])
In general, this is the case, the server is null, directly return the @ "null" string, so in iOS bad judgment, it is best to communicate with the background, if you encounter a null value, return @ "", to make a judgment
Nil and nil and null judgments