Resolves an issue where the array obtained from the server is __nscfconstantstring and "" has no space string

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243

Problem

The project encountered a bug, the data obtained from the server is like this
{
Status = 1,
data = [
{
UID = 161,
Type = 2,
ID = 79,
Addtime = 1447642148,
Addtime_txt = 2,
...
}]
}

Look very abstract, meaning that we have returned after the visit of the data has a status, a data of a bunch of dictionary array, but ... However, if there is no data in the following array case, the status value will be 0, however, the judge status = = 0 or the Isequaltostring method with the string is not possible, anyway, it can not be done.

And, when status = 0, the value of the underground data array is "" such a string .... Yes, there is no mistake, he is a string, I through the ISA and forced conversion, etc. to get his type is __nscfconstantstring oh, what the hell ... And here if you use [data isequaltostring:@] to judge this, when he is empty time is OK, but if there is value of the collapse, Metrorrhagia, in turn, if using other methods, such as to see if he exists, when there is no time that he is "" This ghost will jump, very damn.

Solve

After hundreds of millions of grass mud Marius over, anyway finally I was referring to the Android client brother approach, directly judging the length of the array, but here sometimes he is not an array is __nscfconstantstring this ghost ... (Someone else's Java array if it is not an array type what will be empty what things, oc This table why even know to give me collapse ...) Metrorrhagia

Nsarray*dataarr =Data[@"Data"];NSLog(@"Dataarr.class =%@", Dataarr.class);if([DataarrIskindofclass:[Nsarray  class]]) {         for(nsdictionary* DICinchDataarr) {Attentionterracemodel * Model=[[attentionterracemodel alloc]Initwithdic:DIC]; [_mary_dataAddObject:Model]; }    }Else{Uialertview*aleat=[[UialertviewAllocInitwithtitle:@"Reminders" message:@"No information for the attention" Delegate: Self Cancelbuttontitle:@"OK" Otherbuttontitles:Nil,Nil];    [Aleat show]; }

I solve this, is to change it to Nsarray and then see if he is an array type, anyway, if you encounter a similar dictionary AH string Ah can also try, as to the internal principle of what the cat guess some, here is not nonsense, have to understand the hope can enlighten under, greatly grateful!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Resolves an issue where the array obtained from the server is __nscfconstantstring and "" has no space string

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.