Request SQL data is present <null>, the workaround

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.