开发者

How to check null from json string

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

Here is my code

NSURL *url =开发者_如何学JAVA [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);.


Try with

if([response isEqualToString:@"[]"])


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

if([response isEqualToString:@"[]"]);


Try ,

if ([response isKindOfClass:[NSNull class]])

This one worked for me ..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜