解析JSON格式的数据时,有的字段为空值

解析JSON格式的数据时,有的字段为空值,这个时候不能像平常的与nil比较,而要

一种做法是

NSString *comDic = [[data objectAtIndex:0]  objectForKey:@"CompanyDicNoHtml"];
  NSInteger length = [[comDic dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES] length];
  if(length != 0){

}这种做法我有验证,是可行的

第二种是用[NSString stringWithFormat:@"%@",[[data objectAtIndex:0]  objectForKey:@"Location"]];

格式化后,再比NIL比较


 

posted on 2010-05-19 09:28  fairycao  阅读(6718)  评论(0编辑  收藏  举报