0

I have to used JSON web Services for Login Validation, If Data become send is true then i catch it but How Can i handle if i get's null, Is there any method to compare null object ?

my code is like this

  NSMutableDictionary *jons =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@",jons);

NSMutableArray *rnameary = [jons  objectForKey:@"posts"];
NSLog(@" rname Arry is : %@",rnameary );

NSLog(@" Rname count is %d",[rnameary count]);

if([rnameary isEqual:[NSNull class]]) {
   NSLog(@"%d",[rnameary count]);
}

output if Valied user

2012-03-23 12:30:58.353 [1503:f803]  rname Arry is : (
    {
    IsDoctor = 1;
    PHCIDF = 3;
    UserIDP = 9;
    UserName = Manoj;
    isAdmin = 0;
}

)

output is invalied user

2012-03-23 12:29:40.944 [1481:f803]  rname Arry is : (
"<null>"

)

ravi
  • 120
  • 1
  • 10

2 Answers2

1

If you could post JSON data it would be easier to identify problem, but my first guess is that object for key "posts" is not an array.

ksh
  • 1,894
  • 19
  • 20
1

check this out(i think it should work):

if(rnameary){
     //your stuff here
}
Harshit Gupta
  • 1,200
  • 12
  • 27