Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check null from json string

Tags:

json

iphone

When a JSON Response has no data, it will return Response: [ ].

Here is my code

NSURL *url = [NSURL URLWithString:urlString];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];


    [request startSynchronous];
    NSError *error = [request error];

    NSString *response =nil;
    if (!error) {
        response = [request responseString];

        NSLog(@"Response: %@",response);
}

How should I check whether the response has a value or not?

I tried if([response isEqualToString:@""]|| [response length]==0) but it is not working. I also tried if(response == nil);.

like image 308
iProgrammer Avatar asked Mar 22 '26 20:03

iProgrammer


2 Answers

Try with

if([response isEqualToString:@"[]"])
like image 180
Joze Avatar answered Mar 25 '26 10:03

Joze


Well... If the answer when JSON has no answer is [] you could try:

if([response isEqualToString:@"[]"]);
like image 41
Marsson Avatar answered Mar 25 '26 10:03

Marsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!