Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check Null data parameter in json array or dictionary object in iPhone

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 477
    Comment on it

    If some parameter is missing in json or dictionary. For example-

    json = (
     {
                "created_time" = "2013-11-18T14:40:37+0000";
                from =                 {
                    id = 15400100;
                    name = "Alexandra";
                };
                id = "430737890381371_26";
                message = "adding Emily...can we dress up as politically incorrect native americans and pilgrims for this? ";
            },
                        {
                "created_time" = "2013-11-18T18:39:49+0000";
                from =                 {
                    id = 793231520;
                    name = "Danielle";
                };
                id = "430737890381371_27";
            },
                        {
                "created_time" = "2013-11-18T20:47:47+0000";
                from =                 {
                    id = 100000375798578;
                    name = "Kutney";
                };
                id = "430737890381371_29";
                message = "Sounds super. Wish I was in town.";
            },
    

    )

    In the above example the message param is missing. To resolve or identify this, we should put a condition. Please see the solution below..

    Solution is :-

    NSString *text = [NSString stringWithFormat:@"%@",[[json valueForKey:@"message"] objectAtIndex:i]];
                    if ([text isEqualToString:@"<null>"] || text.length<=0) {
                       // Do your code here.....
                    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: